PdfDocument.Pages Property
Obtains to the collection of document pages.
Namespace: DevExpress.Pdf
Assembly: DevExpress.Pdf.v24.2.Core.dll
NuGet Package: DevExpress.Pdf.Core
#Declaration
#Property Value
Type | Description |
---|---|
IList<Pdf |
A collection of Pdf |
#Remarks
The Pages
property obtian a list of document pages. Access a specific page by its index.
#Add a New Page
Use the following API to append or insert a new page:
Method | Description |
---|---|
Pdf |
Appends an empty page. |
Pdf |
Inserts a page at a specified position (page number). |
The following code adds a new page to a document:
using DevExpress.Pdf;
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
processor.LoadDocument("..\\..\\Document.pdf");
processor.AddNewPage(PdfPaperSize.A4);
processor.SaveDocument("..\\..\\Result.pdf");
}
#Copy a Page from Another Document
The Insert(Int32, T) method allows you to add an extracted page to another PDF file. When you add a page from another document, all page content, including bookmarks referring to this page, is copied to the resulting document.
The code sample below copies a page from one PDF document to another.
using DevExpress.Pdf;
using (PdfDocumentProcessor source = new PdfDocumentProcessor())
{
source.LoadDocument("..\\..\\Document1.pdf");
using (PdfDocumentProcessor target = new PdfDocumentProcessor())
{
target.LoadDocument("..\\..\\Document2.pdf");
target.Document.Pages.Insert(3, source.Document.Pages[0]);
target.SaveDocument("..\\..\\Result.pdf");
}
}
#Extract a Page
Use the Add(T) method to add pages to the collection. When you add a page from another document, all page content, including bookmarks referring to this page, is copied to the resulting document.
using DevExpress.Pdf;
using (PdfDocumentProcessor source = new PdfDocumentProcessor())
{
source.LoadDocument("..\\..\\Document.pdf");
using (PdfDocumentProcessor target = new PdfDocumentProcessor())
{
target.CreateEmptyDocument("..\\..\\ExtractedFirstPage.pdf");
target.Document.Pages.Add(source.Document.Pages[0]);
}
}
#Delete a Page
Call the PdfDocumentProcessor.DeletePage method to remove a page from a document. The PdfDocumentProcessor.DeletePages method removes a list of pages form a document.
The code sample below deletes odd-numbered pages in a document, starting with the last odd-numbered page.
using DevExpress.Pdf;
using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor())
{
pdfDocumentProcessor.LoadDocument("..\\..\\docs\\TextDelete.pdf");
for (int i = pdfDocumentProcessor.Document.Pages.Count; i > 0; i--)
if (i % 2 != 0)
{
pdfDocumentProcessor.DeletePage(i);
}
pdfDocumentProcessor.SaveDocument("..\\..\\docs\\Deleted.pdf");
}
#Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the Pages property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.