Class PdfDocumentPageCollection
Implements a virtual collection of all pages in the document.
Inheritance
Implements
Inherited Members
Namespace: Syncfusion.Pdf
Assembly: Syncfusion.Pdf.Base.dll
Syntax
public class PdfDocumentPageCollection : IEnumerable
Examples
//Load an existing document.
PdfLoadedDocument ldoc = new PdfLoadedDocument("input.pdf");
//Create a new document.
PdfDocument doc = new PdfDocument();
int startIndex = 0;
int endIndex = ldoc.Pages.Count - 1;
//Importing pages from source document.
doc.ImportPageRange(ldoc, startIndex, endIndex);
//Get all the pages fron new document.
PdfDocumentPageCollection docPages = doc.Pages;
int newCount = 0;
//Parse through pages from page collection.
foreach (PdfPageBase page in docPages)
{
newCount++;
}
//Save and close the document.
doc.Save("Output.pdf");
doc.Close(true);
ldoc.Close(true);
'Load an existing document.
Dim ldoc As PdfLoadedDocument = New PdfLoadedDocument("input.pdf")
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
Dim startIndex As Integer = 0
Dim endIndex As Integer = ldoc.Pages.Count - 1
'Importing pages from source document.
doc.ImportPageRange(ldoc, startIndex, endIndex)
'Get all the pages from new document.
Dim docPages As PdfDocumentPageCollection = doc.Pages
Dim newCount As Integer = 0
'Parse through pages from page collection.
For Each page As PdfPageBase In docPages
newCount += 1
Next
'Save and close the document.
doc.Save("Output.pdf")
doc.Close(True)
ldoc.Close(True)
Properties
Count
Gets the total number of the pages.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Examples
//Load an existing document.
PdfLoadedDocument ldoc = new PdfLoadedDocument("input.pdf");
//Create a new document.
PdfDocument doc = new PdfDocument();
int startIndex = 0;
int endIndex = ldoc.Pages.Count - 1;
//Importing pages from source document.
doc.ImportPageRange(ldoc, startIndex, endIndex);
//Get all the pages fron new document.
PdfDocumentPageCollection docPages = doc.Pages;
//Get total page count.
int newCount = docPages.Count;
//Save and close the document.
doc.Save("Output.pdf");
doc.Close(true);
ldoc.Close(true);
'Load an existing document.
Dim ldoc As PdfLoadedDocument = New PdfLoadedDocument("input.pdf")
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
Dim startIndex As Integer = 0
Dim endIndex As Integer = ldoc.Pages.Count - 1
'Importing pages from source document.
doc.ImportPageRange(ldoc, startIndex, endIndex)
'Get all the pages fron new document.
Dim docPages As PdfDocumentPageCollection = doc.Pages
'Get total page count.
Dim newCount As Integer = docPages.Count
'Save and close the document.
doc.Save("Output.pdf")
doc.Close(True)
ldoc.Close(True)
See Also
Item[Int32]
Gets a page by its index in the document.
Declaration
public PdfPage this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index |
Property Value
Type | Description |
---|---|
PdfPage |
Examples
//Load an existing document.
PdfLoadedDocument ldoc = new PdfLoadedDocument("input.pdf");
//Create a new document.
PdfDocument doc = new PdfDocument();
int startIndex = 0;
int endIndex = ldoc.Pages.Count - 1;
//Importing pages from source document.
doc.ImportPageRange(ldoc, startIndex, endIndex);
//Get all the pages fron new document.
PdfDocumentPageCollection docPages = doc.Pages;
//Gets a page by its index in the document.
PdfPage page = docPages[0] as PdfPage;
//Save and close the document.
doc.Save("Output.pdf");
doc.Close(true);
ldoc.Close(true);
'Load an existing document.
Dim ldoc As PdfLoadedDocument = New PdfLoadedDocument("input.pdf")
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
Dim startIndex As Integer = 0
Dim endIndex As Integer = ldoc.Pages.Count - 1
'Importing pages from source document.
doc.ImportPageRange(ldoc, startIndex, endIndex)
'Get all the pages fron new document.
Dim docPages As PdfDocumentPageCollection = doc.Pages
'Gets a page by its index in the document.
Dim page As PdfPage = TryCast(docPages(0), PdfPage)
'Save and close the document.
doc.Save("Output.pdf")
doc.Close(True)
ldoc.Close(True)
See Also
Methods
Add()
Creates a page and adds it to the last section in the document.
Declaration
public PdfPage Add()
Returns
Type | Description |
---|---|
PdfPage | Created PdfPage object. |
Examples
//Load an existing document.
PdfLoadedDocument ldoc = new PdfLoadedDocument("input.pdf");
//Create a new document.
PdfDocument doc = new PdfDocument();
int startIndex = 0;
int endIndex = ldoc.Pages.Count - 1;
//Importing pages from source document.
doc.ImportPageRange(ldoc, startIndex, endIndex);
//Get all the pages fron new document.
PdfDocumentPageCollection docPages = doc.Pages;
//Add new page in the document.
docPages.Add();
//Save and close the document.
doc.Save("Output.pdf");
doc.Close(true);
ldoc.Close(true);
'Load an existing document.
Dim ldoc As PdfLoadedDocument = New PdfLoadedDocument("input.pdf")
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
Dim startIndex As Integer = 0
Dim endIndex As Integer = ldoc.Pages.Count - 1
'Importing pages from source document.
doc.ImportPageRange(ldoc, startIndex, endIndex)
'Get all the pages fron new document.
Dim docPages As PdfDocumentPageCollection = doc.Pages
'Add new page in the document.
docPages.Add()
'Save and close the document.
doc.Save("Output.pdf")
doc.Close(True)
ldoc.Close(True)
See Also
GetEnumerator()
Returns an enumerator that iterates through a collection.
Declaration
public IEnumerator GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator | An System.Collections.IEnumerator object that can be used to iterate through the collection. |
IndexOf(PdfPage)
Declaration
public int IndexOf(PdfPage page)
Parameters
Type | Name | Description |
---|---|---|
PdfPage | page |
Returns
Type | Description |
---|---|
System.Int32 |
Insert(Int32, PdfPage)
Inserts a page at the specified index to the last section in the document.
Declaration
public void Insert(int index, PdfPage page)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the page in the section. |
PdfPage | page | The PdfPage. |
Remarks
Page index start from 0 to (TotalPageCount - 1). Selected index must be within 0 to (TotalPageCount - 1) range.
Examples
//Create new a document.
PdfDocument document = new PdfDocument();
//Load an existing document.
PdfLoadedDocument doc = new PdfLoadedDocument("Input.pdf");
//Importing pages from source document.
document.ImportPageRange(doc, 0, doc.Pages.Count - 1);
//Get all the pages fron new document.
PdfDocumentPageCollection docPages = document.Pages;
//Insert page to the specified index.
docPages.Insert(1, new PdfPage());
docPages.Insert(10, new PdfPage());
//Save and Close the document.
document.Save("Output.pdf");
document.Close(true);
'Create new a document.
Dim document As PdfDocument = New PdfDocument()
'Load an existing document.
Dim doc As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf")
'Importing pages from source document.
document.ImportPageRange(doc, 0, doc.Pages.Count - 1)
'Get all the pages fron new document.
Dim docPages As PdfDocumentPageCollection = document.Pages
'Insert page to the specified index.
docPages.Insert(1, New PdfPage())
docPages.Insert(10, New PdfPage())
'Save and Close the document.
document.Save("Output.pdf")
document.Close(True)
See Also
Insert(Int32, PdfPageBase)
Inserts a loaded page in the new PDF document at specified index.
Declaration
public void Insert(int index, PdfPageBase loadedPage)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index at which the page to be inserted |
PdfPageBase | loadedPage | The page to be inserted |
Remarks
Page index start from 0 to (TotalPageCount - 1). Selected index must be within 0 to (TotalPageCount - 1) range.
Examples
//Create new a document.
PdfDocument document = new PdfDocument();
//Load an existing document.
PdfLoadedDocument doc = new PdfLoadedDocument("Input.pdf");
//Get first page from source document.
PdfLoadedPage lpage = doc.Pages[0] as PdfLoadedPage;
//Importing pages from source document.
document.ImportPageRange(doc, 0, doc.Pages.Count - 1);
//Get all the pages fron new document.
PdfDocumentPageCollection docPages = document.Pages;
//Insert page to the specified index.
docPages.Insert(1, lpage);
//Save and Close the document.
document.Save("Output.pdf");
document.Close(true);
'Create new a document.
Dim document As PdfDocument = New PdfDocument()
'Load an existing document.
Dim doc As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf")
'Get first page from source document.
Dim lpage As PdfLoadedPage = TryCast(doc.Pages(0), PdfLoadedPage)
'Importing pages from source document.
document.ImportPageRange(doc, 0, doc.Pages.Count - 1)
'Insert page to the specified index.
document.Pages.Insert(1, lpage)
'Save and Close the document.
document.Save("Output.pdf")
document.Close(True)
See Also
Events
PageAdded
Represents the method that executes on a PdfDocument when a new page is created.
Declaration
public event PageAddedEventHandler PageAdded
Event Type
Type | Description |
---|---|
PageAddedEventHandler |
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add the event
document.Pages.PageAdded += new PageAddedEventHandler(Pages_PageAdded);
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
//Create font with Bold font style.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
//Draw text in the new page.
page.Graphics.DrawString("Essential PDF", font, PdfBrushes.Black, new PointF(10, 10));
page = document.Pages.Add();
//Saves the document
document.Save("Sample.pdf");
document.Close(true);
//Event handler for PageAdded event
void Pages_PageAdded(object sender, PageAddedEventArgs args)
{
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 10);
args.Page.Graphics.DrawString("New Page", font, PdfBrushes.Black, new PointF(100, 100));
}
'Create a new PDF document.
Dim document As New PdfDocument()
'Add the event
document.Pages.PageAdded += New PageAddedEventHandler(Pages_PageAdded)
'Creates a new page and adds it as the last page of the document
Dim page As PdfPage = document.Pages.Add()
'Create font with Bold font style.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12F, PdfFontStyle.Bold)
'Draw text in the new page.
page.Graphics.DrawString("Essential PDF", font, PdfBrushes.Black, New PointF(10, 10))
page = document.Pages.Add()
'Saves the document
document.Save("Sample.pdf")
document.Close(True)
'Event handler for PageAdded event
Private Sub Pages_PageAdded(sender As Object, args As PageAddedEventArgs)
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 10)
args.Page.Graphics.DrawString("New Page", font, PdfBrushes.Black, New PointF(100, 100))
End Sub