---
title: "Managing PDF page order | Nutrient .NET SDK"
canonical_url: "https://www.nutrient.io/guides/dotnet/csharp/editor/manage-pdf-page-order/"
md_url: "https://www.nutrient.io/guides/dotnet/csharp/editor/manage-pdf-page-order.md"
last_updated: "2026-10-08T00:00:00.000Z"
description: "How to manage PDF page order using Nutrient .NET SDK."
---

# Managing PDF page order

Managing PDF page order programmatically enables teams to automate document assembly, reorganize content, and build dynamic PDF workflows. Whether you're building document merging systems, implementing page reordering tools, or creating automated report generators, the page collection API provides complete control over page structure without manual PDF editing.

## How Nutrient helps you achieve this

Nutrient.NET SDK handles PDF page manipulation and document structure management. With the SDK, you don't need to worry about:

- Parsing PDF page tree structures

- Managing page inheritance hierarchies

- Handling content stream updates

- Complex index recalculation after modifications

Instead, Nutrient provides an API that handles all the complexity behind the scenes, letting you focus on your business logic.

## Complete implementation

Below is a complete working example that demonstrates managing PDF page order. Start with the SDK imports:

```csharp

using Nutrient;

```

Open the PDF document and create the editor with [using declarations](https://learn.microsoft.com/dotnet/csharp/language-reference/statements/using) so the runtime disposes both when you're done, preventing resource leaks. `PdfEditor.Edit()` creates a `PdfEditor` instance, and the `PageCollection` property retrieves the page collection. The editor provides methods for accessing and modifying the document's page structure:

```csharp

try
{
    using Document document = Document.Open("input.pdf");
    using PdfEditor editor = PdfEditor.Edit(document);
    var pages = editor.PageCollection;
    Console.WriteLine($"Document has {pages.Count} page(s)");

```

The following lines demonstrate different ways to access pages. You can get the first or last page directly, or access any page by its 1-based page number. Each page object provides properties like dimensions and rotation:

```csharp

    var firstPage = pages.First?? throw new InvalidOperationException("The document has no pages.");
    Console.WriteLine($"First page - Width: {firstPage.Width}, Height: {firstPage.Height}");

    var lastPage = pages.Last?? throw new InvalidOperationException("The document has no pages.");
    Console.WriteLine($"Last page - Width: {lastPage.Width}, Height: {lastPage.Height}");

    var page1 = pages.GetPage(1);
    Console.WriteLine($"Page 1 - PageNumber: {page1.PageNumber}, Rotation: {page1.Rotation}");

```

The following code block iterates through all pages. Iteration is useful for batch operations like analyzing document structure or applying transformations to every page:

```csharp

    for (int i = 1; i <= pages.Count; i++)
    {
        var page = pages.GetPage(i);
        Console.WriteLine($"Page: {page.Width}x{page.Height}");
    }

```

The following lines add new pages to the document. The first call — `Add` — adds a page with custom dimensions (612×792 points for US Letter), while the second — `Add` — uses predefined page sizes like A4 for convenience:

```csharp

    pages.Add(612.0f, 792.0f);
    Console.WriteLine("Added Letter size page");

    pages.Add(PdfPageSizes.PdfPageSizeA4);
    Console.WriteLine("Added A4 page");

```

The following code inserts a page at a specific position. The `Insert` method takes an index and dimensions, allowing you to place pages precisely within the document structure rather than just appending:

```csharp

    pages.Insert(0, 500.0f, 700.0f);
    Console.WriteLine("Inserted page at index 0");

```

The following code blocks demonstrate page reordering operations. The `Swap` method exchanges two pages by index, while `MoveTo` relocates a page from one position to another, shifting intervening pages automatically:

```csharp

    pages.Swap(0, 1);
    Console.WriteLine("Swapped pages at index 0 and 1");

    pages.MoveTo(0, 2);
    Console.WriteLine("Moved page from index 0 to index 2");

```

The following code removes a page by index with `RemoveAt`. The example removes the last page by using the current page count minus one, demonstrating safe index calculation for removal operations. The final code block then saves the changes to a new file. The `catch` block handles potential errors using `NutrientException`.

```csharp

    pages.RemoveAt(pages.Count - 1);
    Console.WriteLine("Removed last page");

    editor.SaveAs("output.pdf");
    Console.WriteLine("Successfully saved to output.pdf");
}
catch (NutrientException e)
{
    Console.Error.WriteLine($"Error: {e.Message}");
    Environment.Exit(1);
}

```

## Conclusion

The page management logic consists of several key operations:

1. Open the document and create an editor.

2. Access the page collection and individual pages.

3. Iterate through pages for batch operations.

4. Add pages with custom or predefined dimensions.

5. Insert pages at specific positions.

6. Reorder pages using swap and move operations.

7. Remove pages by index.

8. Save the editor.

Nutrient handles PDF page tree structures and content stream updates so you don't need to understand page inheritance hierarchies or manage index recalculation manually.
---

## Related pages

- [Nutrient .NET SDK editor guides](/guides/dotnet/csharp/editor.md)
- [Adding annotations to a PDF document](/guides/dotnet/csharp/editor/add-annotations-to-pdf.md)
- [Adding a custom page to a PDF document](/guides/dotnet/csharp/editor/add-custom-page-to-pdf.md)
- [Adding interactive form fields to a PDF document](/guides/dotnet/csharp/editor/add-form-fields-to-pdf.md)
- [Adding free text annotations to a PDF document](/guides/dotnet/csharp/editor/add-freetext-annotations-to-pdf.md)
- [Adding invisible digital signatures to a PDF document](/guides/dotnet/csharp/editor/add-invisible-signature-to-pdf.md)
- [Adding link annotations to a PDF document](/guides/dotnet/csharp/editor/add-link-annotations-to-pdf.md)
- [Adding redaction annotations to a PDF document](/guides/dotnet/csharp/editor/add-redaction-annotations-to-pdf.md)
- [Adding shape annotations to a PDF document](/guides/dotnet/csharp/editor/add-shape-annotations-to-pdf.md)
- [Adding stamp annotations to a PDF document](/guides/dotnet/csharp/editor/add-stamp-annotations-to-pdf.md)
- [Adding sticky note annotations to a PDF document](/guides/dotnet/csharp/editor/add-sticky-note-annotations-to-pdf.md)
- [Adding text markup annotations to a PDF document](/guides/dotnet/csharp/editor/add-text-markup-annotations-to-pdf.md)
- [Adding visible digital signatures to a PDF document](/guides/dotnet/csharp/editor/add-visible-signature-to-pdf.md)
- [Advanced digital signature workflows](/guides/dotnet/csharp/editor/advanced-digital-signatures.md)
- [Detecting and adding form fields to a PDF document](/guides/dotnet/csharp/editor/detect-and-add-form-fields.md)
- [Editing PDF form fields](/guides/dotnet/csharp/editor/editing-pdf-form-fields.md)
- [Editing PDF metadata with Nutrient .NET SDK](/guides/dotnet/csharp/editor/editing-pdf-metadata.md)
- [Filling PDF form fields](/guides/dotnet/csharp/editor/fill-pdf-form.md)
- [Merging PDFs](/guides/dotnet/csharp/editor/merge-pdf-into-other-pdf.md)

