Aspose.Pdf - PDF文档页数

通过Aspose.Pdf读取PDF文档实际页数

Aspose.Pdf - PDF文档页数

1 API

1
Aspose.Pdf.Document.Pages.Count

2 Documentation

Example below demonstrates how to operate with the document pages:

How to obtain number of pages and how to obtain rectangle of starting page of the document.

1
2
3
4
5
Document document = new Document("sample.pdf");
Pages pages = document.Pages;
Console.WriteLine("Document contains " + pages.Count);
Page page = Pages[1];
Rectangle rect = page.Rect;

3 encapsulation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/// <summary>
/// Get the count of pages in a PDF document
/// </summary>
/// <param name="document"></param>
/// <returns></returns>
public static int GetPdfPageCount(Aspose.Pdf.Document document)
{
return document.Pages.Count;
}

/// <summary>
/// Get the count of pages in a PDF document
/// </summary>
/// <param name="document"></param>
/// <returns></returns>
public static int GetPdfPageCount(string virtualPath)
{
Aspose.Pdf.Document document = new Aspose.Pdf.Document(HostingEnvironment.MapPath(virtualPath));
return GetPdfPageCount(document);
}