---
title: "Managing PDF page order | Nutrient Java SDK"
canonical_url: "https://www.nutrient.io/guides/java/editor/manage-pdf-page-order/"
md_url: "https://www.nutrient.io/guides/java/editor/manage-pdf-page-order.md"
last_updated: "2026-06-09T10:26:34.600Z"
description: "How to manage PDF page order using Nutrient Java SDK."
---

# Managing PDF page order

Use page-order operations to assemble and reorganize PDF documents.

Common use cases include:

- Reordering report sections

- Inserting cover and divider pages

- Building document assembly pipelines

- Removing unwanted pages before export

This guide shows how to add, insert, move, swap, and remove pages.

[Download sample](https://www.nutrient.io/downloads/samples/java/manage-pdf-page-order.zip)

## How Nutrient helps

Nutrient Java SDK handles page manipulation and document structure updates.

The SDK handles:

- Parsing PDF page tree structures and object references

- Managing page inheritance hierarchies and resource dictionaries

- Handling content stream updates and media box adjustments

- Complex index recalculation after modifications and page tree rebalancing

## Complete implementation

This example demonstrates common page-order operations in one workflow:

```java

package io.nutrient.Sample;

import io.nutrient.sdk.*;
import io.nutrient.sdk.editors.*;
import io.nutrient.sdk.editors.pdf.pages.*;
import io.nutrient.sdk.enums.*;

public class ManagePdfPageOrder {

```

Create the `main` method as the sample entry point:

```java

    public static void main(String[] args) {

```

Open the document with try-with-resources, create an editor, and get the page collection:

```java

        try (Document document = Document.open("input.pdf")) {
            PdfEditor editor = PdfEditor.edit(document);
            PdfPageCollection pages = editor.getPageCollection();
            int initialCount = pages.getCount();

```

Access pages in different ways:

- First page with `getFirst()`

- Last page with `getLast()`

- Specific page by 1-based number with `getPage(1)`

```java

            PdfPage firstPage = pages.getFirst();
            System.out.println("First page - Width: " + firstPage.getWidth() + ", Height: " + firstPage.getHeight());

            PdfPage lastPage = pages.getLast();
            System.out.println("Last page - Width: " + lastPage.getWidth() + ", Height: " + lastPage.getHeight());

            PdfPage page1 = pages.getPage(1);
            System.out.println("Page 1 - PageNumber: " + page1.getPageNumber() + ", Rotation: " + page1.getRotation());

```

Iterate through pages for analysis or batch operations:

```java

            for (PdfPage page : pages) {
                System.out.println("Page: " + page.getWidth() + "x" + page.getHeight());
            }

```

Add pages to the end of the document:

- Custom size with `add(width, height)`

- Predefined size with `add(PdfPageSizes.…)`

```java

            PdfPage newPage = pages.add(612.0f, 792.0f);
            System.out.println("Added Letter size page");

            PdfPage a4Page = pages.add(PdfPageSizes.PdfPageSizeA4);
            System.out.println("Added A4 page");

```

Insert a page at a specific index with `insert(index, width, height)`:

```java

            PdfPage insertedPage = pages.insert(0, 500.0f, 700.0f);
            System.out.println("Inserted page at index 0");

```

Reorder pages with:

- `swap(indexA, indexB)` to exchange two pages

- `moveTo(fromIndex, toIndex)` to relocate one page

```java

            pages.swap(0, 1);
            System.out.println("Swapped pages at index 0 and 1");

            pages.moveTo(0, 2);
            System.out.println("Moved page from index 0 to index 2");

```

Remove a page by index.

In this sample, the last page is removed with `pages.getCount() - 1` (zero-based index):

```java

            pages.removeAt(pages.getCount() - 1);
            System.out.println("Removed last page");

            editor.saveAs("output.pdf");
            editor.close();
        } catch (Exception e) {
            System.err.println("Error: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

```

## Conclusion

Use this workflow to manage PDF page order:

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 and close the editor.

For related document workflows, refer to the [Java SDK guides](https://www.nutrient.io/guides/java.md).
---

## Related pages

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

