This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /api/csharp/editors/pdf/pages/pdf-page-collection.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. 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

NameTypeDescription
widthfloatWidth of the new page in points.
heightfloatHeight 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

NameTypeDescription
pageSizePdfPageSizesThe 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

NameTypeDescription
pageNumberintThe 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

NameTypeDescription
indexintThe 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

NameTypeDescription
indexintThe 0-based index at which to insert the new page.
widthfloatWidth of the new page in points.
heightfloatHeight 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

NameTypeDescription
indexintThe 0-based index at which to insert the new page.
pageSizePdfPageSizesThe 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

NameTypeDescription
sourceIndexintThe 0-based index of the page to move.
destinationIndexintThe 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

NameTypeDescription
indexintThe 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

NameTypeDescription
index1intThe 0-based index of the first page.
index2intThe 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.