Skip to footer content
USING IRONPDF

How to Move PDF Pages in C# with IronPDF

How to Move PDF Pages in C#: IronPDF page reordering and manipulation

Moving pages within a PDF document (or transferring them between two documents) is a frequent requirement when organizing reports, assembling monthly newsletters, or restructuring multi-section files before delivery. With IronPDF, the entire operation takes just a few lines of C# code.

This article walks through four practical scenarios: moving a single page to a new position within a document, reordering multiple pages at once, transferring pages between two PDF files, and understanding the common use cases that drive these workflows. Each scenario includes a working code example and an output image showing the result.

Start your free trial to follow along with the examples below.

How Do You Get Started with IronPDF?

Add IronPDF to any .NET project using the NuGet Package Manager Console or the .NET CLI. The package targets .NET Standard 2.0 and runs on .NET Framework 4.6.2+, .NET Core, and all modern .NET versions including .NET 8 and .NET 10.

dotnet add package IronPdf
dotnet add package IronPdf
SHELL

After installation, add using IronPdf; at the top of your C# file. A valid license key unlocks full commercial use; a free trial license covers evaluation and development. Set the key once before calling any API:

IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
$vbLabelText   $csharpLabel

With the package referenced and the license configured, every example in this article will compile and run without modification. The IronPDF NuGet package installs all required dependencies automatically; no additional native binaries or runtime configuration is needed on Windows, Linux, or macOS.

How Can a Single Page Be Moved Within a PDF Document?

Moving a page within a PDF document using IronPDF involves three steps: copy the target page, insert it at the new position, and then remove the original. The PdfDocument class provides CopyPage, InsertPdf, and RemovePage to handle each part of this operation.

The following code demonstrates moving the last page of a document to the beginning:

using IronPdf;

// Load the PDF document from the file system
var pdf = PdfDocument.FromFile("report.pdf");

// Get the zero-based index of the last page
int lastPageIndex = pdf.PageCount - 1;

// Copy the last page into a standalone PdfDocument
var pageToCopy = pdf.CopyPage(lastPageIndex);

// Insert the copied page at position 0 (the first page slot)
pdf.InsertPdf(pageToCopy, 0);

// The original last page has shifted down by one; remove it
pdf.RemovePage(lastPageIndex + 1);

// Save the reordered document to a new file
pdf.SaveAs("report-reorganized.pdf");
using IronPdf;

// Load the PDF document from the file system
var pdf = PdfDocument.FromFile("report.pdf");

// Get the zero-based index of the last page
int lastPageIndex = pdf.PageCount - 1;

// Copy the last page into a standalone PdfDocument
var pageToCopy = pdf.CopyPage(lastPageIndex);

// Insert the copied page at position 0 (the first page slot)
pdf.InsertPdf(pageToCopy, 0);

// The original last page has shifted down by one; remove it
pdf.RemovePage(lastPageIndex + 1);

// Save the reordered document to a new file
pdf.SaveAs("report-reorganized.pdf");
$vbLabelText   $csharpLabel

Rearranged PDF Output

How to Move PDF Pages in C#: Image 2 - Rearranged PDF with the last page moved to the beginning

The code loads a PDF file and calls CopyPage to extract the last page by its zero-based index. IronPDF uses zero-based page numbering throughout its API, so the first page is index 0 and the last is PageCount - 1. After inserting the copy at position 0, the original page shifts down by one position in the index sequence; the removal call accounts for this by targeting lastPageIndex + 1 rather than lastPageIndex. Passing an out-of-range index throws an ArgumentOutOfRangeException, so always verify the page count before operating on edge positions.

For a deeper look at the individual copy and delete operations, the Add, Copy & Delete PDF Pages guide covers each method in detail.

How Does Zero-Based Page Indexing Affect the Removal Step?

Because insertion shifts all subsequent page indexes up by one, the original page ends up one position further than expected after a copy-and-insert. The pattern pdf.RemovePage(lastPageIndex + 1) captures this shift. The same principle applies when moving pages from the middle of a document: any page originally at index N that sits after the insertion point will be at index N+1 once the copy is inserted before it.

Validating index calculations before saving prevents silent ordering errors, particularly in batch pipelines where documents vary in length. A quick check against pdf.PageCount before each operation keeps the logic correct regardless of document size.

What Is the Process for Moving Several Pages at Once?

When multiple pages need to be relocated, CopyPages extracts a specific set of pages in a single call. The method accepts a list of zero-based page indexes and returns a new PdfDocument containing only those pages, in the order specified. This approach suits scenarios such as moving a contiguous block of appendix pages to the end of a report, or pulling a set of summary pages to the front.

using IronPdf;
using System.Collections.Generic;

// Load the quarterly report
var pdf = PdfDocument.FromFile("quarterly-report.pdf");

// Copy pages at indexes 1 and 2 (the second and third pages)
var selectedPages = pdf.CopyPages(new List<int> { 1, 2 });

// Append the copied pages to the end of the original document
var result = PdfDocument.Merge(pdf, selectedPages);

// Remove the originals at their former positions (now indexes 1 and 2)
result.RemovePages(new List<int> { 1, 2 });

// Write the reordered result to a new path
result.SaveAs("quarterly-report-reordered.pdf");
using IronPdf;
using System.Collections.Generic;

// Load the quarterly report
var pdf = PdfDocument.FromFile("quarterly-report.pdf");

// Copy pages at indexes 1 and 2 (the second and third pages)
var selectedPages = pdf.CopyPages(new List<int> { 1, 2 });

// Append the copied pages to the end of the original document
var result = PdfDocument.Merge(pdf, selectedPages);

// Remove the originals at their former positions (now indexes 1 and 2)
result.RemovePages(new List<int> { 1, 2 });

// Write the reordered result to a new path
result.SaveAs("quarterly-report-reordered.pdf");
$vbLabelText   $csharpLabel

Multiple-Page Reorder Output

How to Move PDF Pages in C#: Image 3 - Quarterly report with pages 2 and 3 moved to the end of the document

The code copies two pages from the source document, merges them onto the end using PdfDocument.Merge, and then removes the originals to complete the reorder. The Merge method returns a new PdfDocument object that combines both inputs in sequence: the original document followed by the extracted pages. Removing the now-duplicated originals leaves the final document in the intended order without any redundant content.

The RemovePages method accepts a list of zero-based indexes and removes all specified pages in a single pass. When removing multiple pages, supply all the indexes in one call rather than calling RemovePage in a loop, as each individual removal shifts the remaining indexes and can cause off-by-one errors.

The Merge or Split PDFs tutorial covers additional strategies for combining and dividing documents, including splitting by page range.

How Do You Handle Non-Contiguous Page Groups?

CopyPages accepts any IEnumerable<int>, so non-contiguous pages are supported naturally. Pass new List<int> { 0, 3, 7 } to copy the first, fourth, and eighth pages into a single document in that order. The index list does not need to be sorted, giving full control over the output sequence. This flexibility is useful when assembling a custom document from specific pages across a long source file, such as pulling only the executive summary pages from a multi-chapter report.

If the intent is to fully reorder a document rather than move a subset, building an index array that lists all page positions in the desired order and passing it to CopyPages creates the reordered document in one operation. The Rearrange Pages in PDF C# tutorial covers this full-document reordering pattern in depth.

How Do You Move Pages Between Two PDF Files?

Transferring pages from one PDF document to another follows the same copy-insert pattern, applied across two separate PdfDocument instances. This is the standard approach when consolidating content from multiple source files: for example, moving selected approval pages from a draft into the final contract document.

using IronPdf;

// Load the source and destination documents
var sourceDoc = PdfDocument.FromFile("source-document.pdf");
var destinationDoc = PdfDocument.FromFile("destination-document.pdf");

// Extract the first page (index 0) from the source document
var pageToMove = sourceDoc.CopyPage(0);

// Insert the extracted page at position 2 in the destination (third page slot)
destinationDoc.InsertPdf(pageToMove, 2);

// Save the updated destination document
destinationDoc.SaveAs("destination-document-updated.pdf");

// Remove the transferred page from the source and save separately
sourceDoc.RemovePage(0);
sourceDoc.SaveAs("source-document-updated.pdf");
using IronPdf;

// Load the source and destination documents
var sourceDoc = PdfDocument.FromFile("source-document.pdf");
var destinationDoc = PdfDocument.FromFile("destination-document.pdf");

// Extract the first page (index 0) from the source document
var pageToMove = sourceDoc.CopyPage(0);

// Insert the extracted page at position 2 in the destination (third page slot)
destinationDoc.InsertPdf(pageToMove, 2);

// Save the updated destination document
destinationDoc.SaveAs("destination-document-updated.pdf");

// Remove the transferred page from the source and save separately
sourceDoc.RemovePage(0);
sourceDoc.SaveAs("source-document-updated.pdf");
$vbLabelText   $csharpLabel

Cross-Document Transfer Output

How to Move PDF Pages in C#: Image 4 - Destination document after receiving page from source document

The code loads two documents independently, copies a page from the source using CopyPage, and inserts it into the destination at the specified index using InsertPdf. The source and destination are saved as separate files at different paths, so neither overwrites the other during the operation. Saving the destination first and the source second is safe because CopyPage produces an independent copy; the source document is not modified until RemovePage is called.

Both SaveAs calls write to the file system, but IronPDF also supports in-memory workflows through BinaryData and Stream output methods on PdfDocument. This is useful in web applications where a modified PDF needs to be returned as an HTTP response without writing to disk. The Transform PDF Pages guide covers additional in-memory manipulation patterns.

How Do You Preserve Bookmarks and Annotations When Moving Pages?

When a page is copied with CopyPage, IronPDF preserves the visual content of the page including text, images, form fields, and rendering properties. Outlines (bookmarks) that reference only the moved page travel with the copy, but cross-document bookmark hierarchies that reference multiple pages are not automatically updated. For documents with complex bookmark trees, review the output in a PDF reader after moving pages to verify that internal navigation links point to the correct destinations.

Annotations and form field data embedded directly on the page layer are preserved through the copy operation. If the source document uses named destinations for internal links, those destinations retain their names in the copied page but the links in other parts of the destination document will not resolve them unless the named destinations are registered in the destination document's catalog.

What Are Common Use Cases for Reordering PDF Pages?

Developers need to move and rearrange PDF pages across a wide range of practical scenarios. The PDF page model defined in the PDF specification represents each page as an independent object in the document's page tree, which is why copy-insert-remove operations on individual pages are always valid regardless of document length. Understanding the patterns helps when designing document processing pipelines that handle varied input structures.

Common scenarios for moving and reordering PDF pages in .NET applications
ScenarioTypical OperationIronPDF Methods
Monthly newsletter assemblyMove cover page or table of contents to the frontCopyPage, InsertPdf, RemovePage
Report generationReposition summary pages or insert section dividersCopyPages, Merge, RemovePages
Document consolidationPull selected pages from multiple source files into one outputCopyPage, InsertPdf, SaveAs
Archive reorganizationReorder chronological or categorical pages for reference filesCopyPages, Merge, RemovePages
Contract preparationMove approval or signature pages to the required positionCopyPage, InsertPdf, RemovePage

Beyond page manipulation, IronPDF supports a full range of document operations in the same pipeline. Adding headers and footers, applying watermarks, and adding digital signatures are all available through the same PdfDocument API, so multiple transformations can be chained before the final save. The IronPDF features page provides an overview of every available capability.

For automation scenarios where page positions are determined by document content (for example, inserting an approval page after finding a specific section), the Edit PDF Files tutorial covers text search and content-driven manipulation techniques that can be combined with page reordering.

How Do You Handle Performance When Moving Pages in Large Documents?

Page manipulation in IronPDF operates on the in-memory document representation, so performance scales with document size and the number of operations applied. For large PDFs, a few patterns help keep processing efficient.

Working with the minimum necessary page count reduces memory overhead. Instead of loading a 500-page document to move two pages, split the document into sections first using CopyPages, perform the reorder on the smaller set, and then reassemble with Merge. The Split PDF Pages example demonstrates this decompose-and-reassemble pattern.

For batch processing pipelines that move pages across many documents, dispose of PdfDocument instances after each save to release memory promptly. PdfDocument implements IDisposable, so wrapping each instance in a using statement ensures deterministic cleanup even when exceptions occur mid-pipeline.

using IronPdf;

// Use 'using' declarations to ensure deterministic disposal
using var source = PdfDocument.FromFile("source-large.pdf");
using var destination = PdfDocument.FromFile("destination-large.pdf");

var pageToTransfer = source.CopyPage(0);
destination.InsertPdf(pageToTransfer, 0);

destination.SaveAs("destination-updated.pdf");
source.RemovePage(0);
source.SaveAs("source-updated.pdf");
using IronPdf;

// Use 'using' declarations to ensure deterministic disposal
using var source = PdfDocument.FromFile("source-large.pdf");
using var destination = PdfDocument.FromFile("destination-large.pdf");

var pageToTransfer = source.CopyPage(0);
destination.InsertPdf(pageToTransfer, 0);

destination.SaveAs("destination-updated.pdf");
source.RemovePage(0);
source.SaveAs("source-updated.pdf");
$vbLabelText   $csharpLabel

The using declarations here ensure that both PdfDocument objects are disposed after the SaveAs calls complete, freeing the underlying memory buffers immediately. This pattern is particularly important in ASP.NET Core applications where many requests may process documents concurrently on the same server. For additional API details on memory-safe document handling, consult the IronPDF API Reference.

What Are Your Next Steps?

Moving and reordering PDF pages in C# requires three IronPDF methods: CopyPage, InsertPdf, and RemovePage, applied in a copy-insert-remove sequence. The same pattern scales from moving a single page within one document to transferring batches of pages across multiple files. IronPDF also works in VB.NET with the same API, and the page-manipulation methods are available across all supported .NET platforms including .NET 8 and .NET 10.

To explore related capabilities, the Add, Copy & Delete PDF Pages guide covers every page-level method in depth. For full-document reordering using a page-index array, the Rearrange Pages in PDF C# article walks through that approach.

Ready to add PDF page manipulation to your project? Start a free trial to access all IronPDF features during development, or purchase a license to deploy to production today.

Frequently Asked Questions

How do you move a page to a different position in a PDF using C#?

Use IronPDF's three-step pattern: call CopyPage(pageIndex) to extract the page, call InsertPdf(copiedPage, targetIndex) to place it at the new position, then call RemovePage(originalIndex + 1) to remove the original (adding 1 to account for the index shift caused by the insertion).

How do you move multiple pages at once in IronPDF?

Call CopyPages(new List<int> { 1, 2 }) to extract specific pages by index, then use PdfDocument.Merge(original, copiedPages) to append them, and RemovePages(new List<int> { 1, 2 }) to remove the originals from their former positions.

How do you transfer a page from one PDF file to another in C#?

Load both documents with PdfDocument.FromFile, call CopyPage(index) on the source document, call InsertPdf(page, position) on the destination document, then save each with SaveAs. Optionally remove the transferred page from the source using RemovePage.

Why does removing a page require adding 1 to the original index after an insertion?

When a page is inserted at a position before the original page's index, every subsequent page shifts up by one. If the original page was at index N and you inserted before it, the original is now at index N+1. Always account for this shift when calling RemovePage after InsertPdf.

Does IronPDF use zero-based page indexing?

Yes. IronPDF uses zero-based indexing throughout its API. The first page is at index 0, the second at index 1, and so on. The last page index is PdfDocument.PageCount - 1. Passing an index outside this range throws an ArgumentOutOfRangeException.

Can you move non-contiguous pages using IronPDF?

Yes. The CopyPages method accepts any IEnumerable<int>, so you can pass non-contiguous indexes like new List<int> { 0, 3, 7 }. The pages are returned in the order you specify, not in document order.

Are bookmarks and annotations preserved when moving pages with IronPDF?

Page-level visual content (text, images, form fields) is preserved when using CopyPage. Bookmarks that reference only the moved page travel with the copy. Cross-document bookmark hierarchies referencing multiple pages are not automatically updated, so verify navigation links in the output after moving pages.

How do you dispose of PdfDocument objects properly in a batch pipeline?

Use using var pdf = PdfDocument.FromFile(path); declarations to ensure deterministic disposal after the SaveAs call completes. This releases in-memory buffers immediately rather than waiting for garbage collection, which is critical in high-throughput ASP.NET Core applications.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me