PdfPageCollection
Represents a collection of pages in a PDF document. Provides indexed access to individual PdfPage objects and methods to manipulate the page structure.
using Nutrient;The SDK creates this class through factory methods or other SDK objects.
Collection access
PdfPageCollection implements IReadOnlyList<PdfPage>, so you can index it, read its Count, and iterate it with foreach.
public PdfPage this[int index] { get; }Gets the element at the specified 0-based index. Type: PdfPage
Properties
Count
public int Count { get; }The number of pages in the collection.
Type: int
First
public PdfPage? First { get; }The first page of the document, or null if the document has no pages.
Type: PdfPage?
Last
public PdfPage? Last { get; }The last page of the document, or null if the document has no pages.
Type: PdfPage?
Methods
Add
public PdfPage Add()Adds a new page at the end of the document with the default A4 page size.
Returns: PdfPage - The newly created PdfPage. Throws: NutrientException - Thrown when the operation fails.
public PdfPage Add(float width, float height)Adds a new page at the end of the document with the specified dimensions.
Parameters
| Name | Type | Description |
|---|---|---|
width | float | Width of the new page in points. |
height | float | Height of the new page in points. |
Returns: PdfPage - The newly created PdfPage. Throws: NutrientException - Thrown when the operation fails.
public PdfPage Add(PdfPageSizes pageSize)Adds a new page at the end of the document with a predefined page size.
Parameters
| Name | Type | Description |
|---|---|---|
pageSize | PdfPageSizes | The predefined page size. |
Returns: PdfPage - The newly created PdfPage. Throws: NutrientException - Thrown when the operation fails.
GetPage
public PdfPage GetPage(int pageNumber)Returns a page by its 1-based page number.
Parameters
| Name | Type | Description |
|---|---|---|
pageNumber | int | The 1-based page number. |
Returns: PdfPage - The PdfPage with the specified page number. Throws: NutrientException - Thrown when pageNumber is out of range.
Insert
public PdfPage Insert(int index)Inserts a new page at the specified position with the default A4 page size.
Parameters
| Name | Type | Description |
|---|---|---|
index | int | The 0-based index at which to insert the new page. |
Returns: PdfPage - The newly created PdfPage. Throws: NutrientException - Thrown when index is out of range.
Throws: NutrientException - Thrown when the operation fails.
public PdfPage Insert(int index, float width, float height)Inserts a new page at the specified position with the specified dimensions.
Parameters
| Name | Type | Description |
|---|---|---|
index | int | The 0-based index at which to insert the new page. |
width | float | Width of the new page in points. |
height | float | Height of the new page in points. |
Returns: PdfPage - The newly created PdfPage. Throws: NutrientException - Thrown when index is out of range.
Throws: NutrientException - Thrown when the operation fails.
public PdfPage Insert(int index, PdfPageSizes pageSize)Inserts a new page at the specified position with a predefined page size.
Parameters
| Name | Type | Description |
|---|---|---|
index | int | The 0-based index at which to insert the new page. |
pageSize | PdfPageSizes | The predefined page size. |
Returns: PdfPage - The newly created PdfPage. Throws: NutrientException - Thrown when index is out of range.
Throws: NutrientException - Thrown when the operation fails.
MoveTo
public void MoveTo(int sourceIndex, int destinationIndex)Moves a page from one position to another.
Parameters
| Name | Type | Description |
|---|---|---|
sourceIndex | int | The 0-based index of the page to move. |
destinationIndex | int | The 0-based index of the destination position. |
Throws: NutrientException - Thrown when either index is out of range.
Throws: NutrientException - Thrown when the operation fails.
RemoveAt
public void RemoveAt(int index)Removes the page at the specified 0-based index.
Parameters
| Name | Type | Description |
|---|---|---|
index | int | The 0-based index of the page to remove. |
Throws: NutrientException - Thrown when index is out of range.
Throws: NutrientException - Thrown when the operation fails.
Swap
public void Swap(int index1, int index2)Swaps two pages in the document.
Parameters
| Name | Type | Description |
|---|---|---|
index1 | int | The 0-based index of the first page. |
index2 | int | The 0-based index of the second page. |
Throws: NutrientException - Thrown when either index is out of range.
Throws: NutrientException - Thrown when the operation fails.
Resource management
public void Dispose()PdfPageCollection implements IDisposable. Call Dispose() or use a C# using declaration to release its native handle right away. If you don’t, the handle is released when the object is garbage collected.