DocumentPageCount Property

Gets the number of pages in the document as calculated by the most recent page layout operation.

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

Syntax

public int PageCount { get; }

Property Value

Type: Int32

Examples

Shows how to invoke page layout and retrieve the number of pages in the document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert text spanning 3 pages
builder.Write("Page 1");
builder.InsertBreak(BreakType.PageBreak);
builder.Write("Page 2");
builder.InsertBreak(BreakType.PageBreak);
builder.Write("Page 3");

// Get the page count
Assert.AreEqual(3, doc.PageCount);

// Getting the PageCount property invoked the document's page layout to calculate the value
// This operation will not need to be re-done when rendering the document to a save format like .pdf,
// which can save time with larger documents
doc.Save(ArtifactsDir + "Document.GetPageCount.pdf");

See Also