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.9.0


public int PageCount { get; }

Property Value

Type: Int32


Shows how to count the number of pages in the document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Write("Page 1");
builder.Write("Page 2");
builder.Write("Page 3");

// Verify the expected page count of the document.
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 fixed-page save format,
// such as .pdf. So you can save some time, especially with more complex documents.
doc.Save(ArtifactsDir + "Document.GetPageCount.pdf");

See Also