officefileapi-devexpress-dot-pdf-dot-pdfdocument.md
Obtains to the collection of document pages.
Namespace : DevExpress.Pdf
Assembly : DevExpress.Pdf.v25.2.Core.dll
NuGet Package : DevExpress.Pdf.Core
public IList<PdfPage> Pages { get; }
Public ReadOnly Property Pages As IList(Of PdfPage)
| Type | Description |
|---|---|
| IList<PdfPage> |
A collection of PdfPage objects.
|
The Pages property obtian a list of document pages. Access a specific page by its index.
Use the following API to append or insert a new page:
| Method | Description |
|---|---|
| PdfDocumentProcessor.AddNewPage | Appends an empty page. |
| PdfDocumentProcessor.InsertNewPage | 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");
}
Imports DevExpress.Pdf
Using processor As New PdfDocumentProcessor()
processor.LoadDocument("..\..\Document.pdf")
processor.AddNewPage(PdfPaperSize.A4)
processor.SaveDocument("..\..\Result.pdf")
End Using
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.
View Example: How to copy a page from one 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");
}
}
Imports DevExpress.Pdf
Using source As New PdfDocumentProcessor()
source.LoadDocument("..\..\Document1.pdf")
Using target As New PdfDocumentProcessor()
target.LoadDocument("..\..\Document2.pdf")
target.Document.Pages.Insert(3, source.Document.Pages(0))
target.SaveDocument("..\..\Result.pdf")
End Using
End Using
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]);
}
}
Imports DevExpress.Pdf
Using source As New PdfDocumentProcessor()
source.LoadDocument("..\..\Document.pdf")
Using target As New PdfDocumentProcessor()
target.CreateEmptyDocument("..\..\ExtractedFirstPage.pdf")
target.Document.Pages.Add(source.Document.Pages(0))
End Using
End Using
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.
View Example: Delete Pages from PDF
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");
}
Imports DevExpress.Pdf
Using pdfDocumentProcessor As New PdfDocumentProcessor()
pdfDocumentProcessor.LoadDocument("..\..\docs\TextDelete.pdf")
For i As Integer = pdfDocumentProcessor.Document.Pages.Count To 0+1 Step -1
If i Mod 2 <> 0 Then
pdfDocumentProcessor.DeletePage(i)
End If
Next i
pdfDocumentProcessor.SaveDocument("..\..\docs\Deleted.pdf")
End Using
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.
pdf-document-api-extract-pages-from-document/CS/ExtractDocumentPages/Program.cs#L19
target.CreateEmptyDocument("..\\..\\ExtractedPage" + (i + 1).ToString() + ".pdf");
target.Document.Pages.Add(source.Document.Pages[i]);
}
how-to-custom-draw-in-pdf-viewer/CS/PDF_Viewer/Form1.cs#L46
{
PdfPage page = processor.Document.Pages[rect.PageIndex];
PdfRectangle pageCropBox = page.CropBox;
pdf-document-api-add-graphics-to-landscape-and-portrait-pages/CS/CreateGraphics/Program.cs#L27
{
IList<PdfPage> pages = processor.Document.Pages;
for (int i = 0; i < pages.Count; i++)
pdf-document-api-copy-pages/CS/CopyPage/Program.cs#L17
target.LoadDocument("..\\..\\..\\Document2.pdf");
target.Document.Pages.Insert(3, source.Document.Pages[0]);
target.SaveDocument("..\\..\\..\\Result.pdf");
pdf-document-api-replace-form-field-with-image/CS/ReplaceFormFieldWithImage/Program.cs#L25
PdfRectangle rect = widget.Rectangle;
PdfPage page = processor.Document.Pages[widget.PageNumber - 1];
double x = rect.Left - page.CropBox.Left;
pdf-document-api-extract-pages-from-document/VB/ExtractDocumentPages/Program.vb#L14
target.CreateEmptyDocument("..\..\ExtractedPage" & (i + 1).ToString() & ".pdf")
target.Document.Pages.Add(source.Document.Pages(i))
End Using
how-to-custom-draw-in-pdf-viewer/VB/PDF_Viewer/Form1.vb#L42
Using graph As PdfGraphics = processor.CreateGraphics()
Dim page As PdfPage = processor.Document.Pages(rect.PageIndex)
Dim pageCropBox As PdfRectangle = page.CropBox
pdf-document-api-add-graphics-to-landscape-and-portrait-pages/VB/CreateGraphics/Program.vb#L24
Private Shared Sub AddGraphics(ByVal processor As PdfDocumentProcessor, ByVal text As String, ByVal textBrush As DXSolidBrush)
Dim pages As IList(Of PdfPage) = processor.Document.Pages
For i As Integer = 0 To pages.Count - 1
pdf-document-api-copy-pages/VB/CopyPage/Program.vb#L12
target.LoadDocument("..\..\..\Document2.pdf")
target.Document.Pages.Insert(3, source.Document.Pages(0))
target.SaveDocument("..\..\..\Result.pdf")
pdf-document-api-replace-form-field-with-image/VB/ReplaceFormFieldWithImage/Program.vb#L23
Dim rect As PdfRectangle = widget.Rectangle
Dim page As PdfPage = processor.Document.Pages(widget.PageNumber - 1)
Dim x As Double = rect.Left - page.CropBox.Left
See Also