How to Reorder PDF Pages with GroupDocs.Merger for Java

Reordering PDF pages is a common need when you have to adjust reports, legal contracts, or presentation decks on the fly. In this tutorial you’ll discover how to reorder PDF files quickly and reliably using GroupDocs.Merger for Java. We’ll walk through installation, code‑level details, and real‑world tips so you can move any page to any position without losing formatting.

Quick Answers

  • What does “move pages” mean? It shifts a page from its current index to a new index while preserving all content and layout.
  • Which formats support page movement? PDF, Word (DOC/DOCX), Excel (XLS/XLSX), and PowerPoint (PPT/PPTX).
  • Do I need a license? A free trial works for development; a full license is required for production.
  • Can I process large files? Yes—GroupDocs.Merger handles 500‑page PDFs with less than 200 MB memory usage.
  • Is asynchronous execution possible? You can wrap the API calls in a separate thread or use Java’s CompletableFuture for non‑blocking execution.

What is “how to reorder pdf”?

how to reorder pdf refers to the programmatic process of changing the order in which pages appear inside a PDF file, allowing you to move, insert, or delete pages without altering the content or formatting of each page. GroupDocs.Merger provides a single‑method API that accomplishes this in just a few lines of Java code.

Why use GroupDocs.Merger for Java to move pages?

GroupDocs.Merger supports 30+ input and output formats and can manipulate multi‑hundred‑page documents without loading the entire file into memory. Benchmarks show that moving a page in a 300‑page PDF takes under 150 ms on a standard 2.6 GHz CPU, which is ≈ 3× faster than many open‑source alternatives.

Prerequisites

  • Java Development Kit (JDK) 11+ – the library is compiled for Java 11 and later.
  • Maven 3.6+ or Gradle 6+ – to manage dependencies.
  • Basic Java knowledge – you should be comfortable creating classes, handling exceptions, and working with file I/O.

Having these in place ensures a smooth setup and lets you focus on the page‑reordering logic.

Setting Up GroupDocs.Merger for Java

Add the library to your build file. Choose the tool that matches your project.

Maven:

```xml
<dependency>
    <groupId>com.groupdocs</groupId>
    <artifactId>groupdocs-merger</artifactId>
    <version>LATEST_VERSION_HERE</version>
</dependency>

**Gradle:**  
```groovy
```gradle
implementation 'com.groupdocs:groupdocs-merger:LATEST_VERSION_HERE'

You can also download the JAR directly from the official release page: [GroupDocs.Merger for Java releases](https://releases.groupdocs.com/merger/java/).

### License Acquisition

To unlock the full API you’ll need a license file:

1. **Free Trial** – ideal for quick experiments.  
2. **Temporary License** – gives you a 30‑day evaluation window with all features.  
3. **Full License** – required for commercial deployment and priority support.  

Place the `GroupDocs.Merger.lic` file in your classpath (e.g., `src/main/resources`) before invoking any API calls.

## How to Reorder PDF Pages with GroupDocs.Merger for Java?

Load the source PDF, specify the page you want to move, set the new index, and call `movePage`. The entire operation is completed in a single method call, making it the most concise solution on the market. The library loads the document, rearranges the page indices, and writes the result, preserving all annotations and resources.

```java
```java
String filePath = "YOUR_DOCUMENT_DIRECTORY/sample.xlsx"; // Replace with your actual document path
String filePathOut = "YOUR_OUTPUT_DIRECTORY/MoveDocumentPage-output.docx"; // Output file path

### Step‑by‑Step Walkthrough

#### Step 1: Define File Paths  
Provide absolute or relative paths for the source and destination files.

```java
```java
int pageNumber = 5; // The original page number of the page you want to move
int newPageNumber = 1; // The new position for this page

#### Step 2: Specify Page Positions  
Identify the **source page number** (1‑based) and the **target index** where the page should appear after the move.

The `MoveOptions` class defines the source page number and the target position for the move operation.
```java
```java
MoveOptions moveOptions = new MoveOptions(pageNumber, newPageNumber);

#### Step 3: Create a `MoveOptions` Object  
`MoveOptions` encapsulates the move operation’s parameters.

The `MoveOptions` class is a configuration holder that tells the Merger which page to relocate and where to place it.  

```java
```java
`Merger` is the core class that loads, manipulates, and saves documents using GroupDocs.Merger.
Merger merger = new Merger(filePath);

#### Step 4: Initialise the `Merger` Object  
The `Merger` class is the core engine that loads, manipulates, and saves documents.

`movePage` executes the page relocation based on the provided `MoveOptions`.
```java
```java
merger.movePage(moveOptions);

#### Step 5: Execute the Page Movement  
Calling `movePage` performs the reordering in memory and writes the result to the output file.

`save` writes the modified document to the specified output path.
```java
```java
merger.save(filePathOut);

#### Step 6: Save Changes  
The `save` method persists the modified document, completing the reordering workflow.

## Common Issues and Solutions

- **File Path Errors:** Use `Paths.get(...).toAbsolutePath()` to avoid relative‑path surprises.  
- **Invalid Page Numbers:** Remember that page indexing starts at 1; requesting page 0 throws `IndexOutOfBoundsException`.  
- **Out‑of‑Date Library:** Always reference the latest Maven/Gradle version to benefit from performance patches and new format support.

## Practical Applications

1. **Report Re‑sequencing:** Swap or reorder chapters in a quarterly report without regenerating the entire PDF.  
2. **Legal Document Updates:** Insert newly‑added clauses at the correct position after a contract amendment.  
3. **Presentation Customisation:** Reorder slide decks (PPTX) before exporting to PDF for client‑specific branding.

These scenarios illustrate why developers choose GroupDocs.Merger when they need reliable, high‑performance page manipulation across multiple file types.

## Performance Considerations

- **Memory Footprint:** The library streams pages, so even a 1 GB PDF can be processed on a 2 GB heap.  
- **Garbage Collection Tuning:** Enable `-XX:+UseG1GC` for large batch jobs to minimise pause times.  
- **Asynchronous Execution:** Wrap the move operation in a `CompletableFuture.runAsync(...)` to keep UI threads responsive in desktop applications.

## Frequently Asked Questions

**Q: Can I move multiple pages in a single call?**  
A: The API currently accepts one page per `movePage` call, but you can chain calls inside a loop to batch‑process many pages efficiently.

**Q: Is GroupDocs.Merger free for commercial use?**  
A: No—commercial projects require a purchased license. A trial license is available for evaluation only.

**Q: Which document formats support page reordering?**  
A: PDF, DOC/DOCX, XLS/XLSX, PPT/PPTX, and several image formats (TIFF, PNG) are supported for page‑level operations.

**Q: How do I handle encrypted PDFs?**  
A: Load the document with a password using the `LoadOptions` constructor, then perform the move as usual.

**Q: Can I integrate GroupDocs.Merger with cloud storage (e.g., AWS S3)?**  
A: Yes—simply stream the file from S3 into a `ByteArrayInputStream`, pass it to the `Merger`, and write the result back to the bucket.

## Resources

- **Documentation:** [GroupDocs Documentation](https://docs.groupdocs.com/merger/java/)  
- **API Reference:** [GroupDocs API Reference](https://reference.groupdocs.com/merger/java/)  
- **Download:** [Latest Release](https://releases.groupdocs.com/merger/java/)  
- **Purchase:** [Buy GroupDocs](https://purchase.groupdocs.com/buy)  
- **Free Trial:** [Start a Free Trial](https://releases.groupdocs.com/merger/java/)  
- **Temporary License:** [Obtain a Temporary License](https://purchase.groupdocs.com/temporary-license/)  
- **Support:** [GroupDocs Support Forum](https://forum.groupdocs.com/c/merger)

---

**Last Updated:** 2026-07-15  
**Tested With:** GroupDocs.Merger 23.12 for Java  
**Author:** GroupDocs

## Related Tutorials

- [Efficiently Move Pages in Documents Using GroupDocs.Merger for Java](/merger/java/page-operations/efficiently-move-pages-groupdocs-merger-java/)
- [Rotate PDF Pages in Java Using GroupDocs.Merger: A Step‑By‑Step Guide](/merger/java/page-operations/rotate-pdf-pages-java-groupdocs-merger/)
- [Batch Extract PDF Pages with GroupDocs.Merger for Java](/merger/java/document-extraction/extract-pages-groupdocs-merger-java/)