Document Constructor

Creates a blank Word document.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 21.11.0


public Document()


The document paper size is Letter by default. If you want to change page setup, use Section.PageSetup.

After creation, you can use DocumentBuilder to add document content easily.


Shows how to format a run of text using its font property.
Document doc = new Document();
Run run = new Run(doc, "Hello world!");

Aspose.Words.Font font = run.Font;
font.Name = "Courier New";
font.Size = 36;
font.HighlightColor = Color.Yellow;

doc.Save(ArtifactsDir + "Font.CreateFormattedRun.docx");
Shows how to create and load documents.
// There are two ways of creating a Document object using Aspose.Words.
// 1 -  Create a blank document:
Document doc = new Document();

// New Document objects by default come with the minimal set of nodes
// required to begin adding content such as text and shapes: a Section, a Body, and a Paragraph.
doc.FirstSection.Body.FirstParagraph.AppendChild(new Run(doc, "Hello world!"));

// 2 -  Load a document that exists in the local file system:
doc = new Document(MyDir + "Document.docx");

// Loaded documents will have contents that we can access and edit.
Assert.AreEqual("Hello World!", doc.FirstSection.Body.FirstParagraph.GetText().Trim());

// Some operations that need to occur during loading, such as using a password to decrypt a document,
// can be done by passing a LoadOptions object when loading the document.
doc = new Document(MyDir + "Encrypted.docx", new LoadOptions("docPassword"));

Assert.AreEqual("Test encrypted document.", doc.FirstSection.Body.FirstParagraph.GetText().Trim());

ExpandedSee Also