---
title: "PdfPageCollection"
canonical_url: "https://www.nutrient.io/api/csharp/editors/pdf/pages/pdf-page-collection/"
md_url: "https://www.nutrient.io/api/csharp/editors/pdf/pages/pdf-page-collection.md"
last_updated: "2026-10-08T08:55:57.709Z"
description: "Represents a collection of pages in a PDF document. Provides indexed access to individual `PdfPage` objects and methods to manipulate the page structure."
---

Represents a collection of pages in a PDF document. Provides indexed access to individual `PdfPage` objects and methods to manipulate the page structure.

```csharp

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`.

```csharp

public PdfPage this[int index] { get; }

```

Gets the element at the specified 0-based index. **Type:** [`PdfPage`](/api/csharp/editors/pdf/pages/pdf-page/)

## Properties

### Count

```csharp

public int Count { get; }

```

The number of pages in the collection.

**Type:** `int`

### First

```csharp

public PdfPage? First { get; }

```

The first page of the document, or null if the document has no pages.

**Type:** [`PdfPage?`](/api/csharp/editors/pdf/pages/pdf-page/)

### Last

```csharp

public PdfPage? Last { get; }

```

The last page of the document, or null if the document has no pages.

**Type:** [`PdfPage?`](/api/csharp/editors/pdf/pages/pdf-page/)

## Methods

### Add

```csharp

public PdfPage Add()

```

Adds a new page at the end of the document with the default A4 page size.

**Returns:** [`PdfPage`](/api/csharp/editors/pdf/pages/pdf-page/) - The newly created `PdfPage`.

**Throws:** [`NutrientException`](/api/csharp/exceptions/nutrient-exception/) - Thrown when the operation fails.

```csharp

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`](/api/csharp/editors/pdf/pages/pdf-page/) - The newly created `PdfPage`.

**Throws:** [`NutrientException`](/api/csharp/exceptions/nutrient-exception/) - Thrown when the operation fails.

```csharp

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`](/api/csharp/enums/pdf-page-sizes/) | The predefined page size. |

**Returns:** [`PdfPage`](/api/csharp/editors/pdf/pages/pdf-page/) - The newly created `PdfPage`.

**Throws:** [`NutrientException`](/api/csharp/exceptions/nutrient-exception/) - Thrown when the operation fails.

### GetPage

```csharp

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`](/api/csharp/editors/pdf/pages/pdf-page/) - The `PdfPage` with the specified page number.

**Throws:** [`NutrientException`](/api/csharp/exceptions/nutrient-exception/) - Thrown when pageNumber is out of range.

### Insert

```csharp

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`](/api/csharp/editors/pdf/pages/pdf-page/) - The newly created `PdfPage`.

**Throws:** [`NutrientException`](/api/csharp/exceptions/nutrient-exception/) - Thrown when index is out of range.

**Throws:** [`NutrientException`](/api/csharp/exceptions/nutrient-exception/) - Thrown when the operation fails.

```csharp

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`](/api/csharp/editors/pdf/pages/pdf-page/) - The newly created `PdfPage`.

**Throws:** [`NutrientException`](/api/csharp/exceptions/nutrient-exception/) - Thrown when index is out of range.

**Throws:** [`NutrientException`](/api/csharp/exceptions/nutrient-exception/) - Thrown when the operation fails.

```csharp

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`](/api/csharp/enums/pdf-page-sizes/) | The predefined page size.                          |

**Returns:** [`PdfPage`](/api/csharp/editors/pdf/pages/pdf-page/) - The newly created `PdfPage`.

**Throws:** [`NutrientException`](/api/csharp/exceptions/nutrient-exception/) - Thrown when index is out of range.

**Throws:** [`NutrientException`](/api/csharp/exceptions/nutrient-exception/) - Thrown when the operation fails.

### MoveTo

```csharp

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`](/api/csharp/exceptions/nutrient-exception/) - Thrown when either index is out of range.

**Throws:** [`NutrientException`](/api/csharp/exceptions/nutrient-exception/) - Thrown when the operation fails.

### RemoveAt

```csharp

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`](/api/csharp/exceptions/nutrient-exception/) - Thrown when index is out of range.

**Throws:** [`NutrientException`](/api/csharp/exceptions/nutrient-exception/) - Thrown when the operation fails.

### Swap

```csharp

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`](/api/csharp/exceptions/nutrient-exception/) - Thrown when either index is out of range.

**Throws:** [`NutrientException`](/api/csharp/exceptions/nutrient-exception/) - Thrown when the operation fails.

## Resource management

```csharp

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.

---

## Related pages

- [Pages](/api/csharp/editors/pdf/pages.md)
- [Pdf Metadata](/api/csharp/editors/pdf/pages/pdf-metadata.md)
- [Pdf Page](/api/csharp/editors/pdf/pages/pdf-page.md)

