Skip to footer content
USING IRONPDF

How to Rearrange Pages in PDF C# With IronPDF

How to Rearrange Pages in PDF C# With IronPDF: Image 1 - Rearrange Pages in PDFs C#

Rearranging pages in PDF C# programmatically saves hours of manual work when organizing reports, merging content, or removing outdated sections. In this article, we'll show you how to reorder PDF pages, move pages to a new location, copy multiple pages, and delete unwanted content using a .NET library. Install the IronPDF library today and follow along.

IronPdf.PdfDocument.FromFile("input.pdf")
    .CopyPages(new[] { 2, 0, 1, 3 })
    .SaveAs("reordered.pdf");
IronPdf.PdfDocument.FromFile("input.pdf")
    .CopyPages(new[] { 2, 0, 1, 3 })
    .SaveAs("reordered.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

NuGet Install with NuGet

PM >  Install-Package IronPdf

Check out IronPDF on NuGet for quick installation. With over 10 million downloads, it’s transforming PDF development with C#. You can also download the DLL or Windows installer.

How Does Page Reordering Work in C#?

The process to rearrange pages in PDF using C# involves loading the source document, specifying the desired page order through a page index array, and saving the output file. IronPDF provides the CopyPages method to extract and reorder pages from a PDF file into a new PDF document class object.

The following code demonstrates how to reorder pages by creating a new int array that defines the target sequence. Each value in the array represents a page index from the original document, where pages use zero-based indexing (page 0 is the first page).

using IronPdf;
// Load the source document from file path
var pdf = PdfDocument.FromFile("quarterly-report.pdf");
// Define new page order: move page 3 to front, then pages 1, 2, 0
int[] pageOrder = new int[] { 3, 1, 2, 0 };
// Copy each requested page into its own PdfDocument, collect them
var pageDocs = new List<PdfDocument>();
foreach (var idx in pageOrder)
{
    // CopyPage returns a PdfDocument that contains only that page
    var single = pdf.CopyPage(idx);
    pageDocs.Add(single);
}
// Merge the single-page docs into one ordered document
using var merged = PdfDocument.Merge(pageDocs.ToArray());
// Save the new ordered PDF
merged.SaveAs("report-reorganized.pdf");
using IronPdf;
// Load the source document from file path
var pdf = PdfDocument.FromFile("quarterly-report.pdf");
// Define new page order: move page 3 to front, then pages 1, 2, 0
int[] pageOrder = new int[] { 3, 1, 2, 0 };
// Copy each requested page into its own PdfDocument, collect them
var pageDocs = new List<PdfDocument>();
foreach (var idx in pageOrder)
{
    // CopyPage returns a PdfDocument that contains only that page
    var single = pdf.CopyPage(idx);
    pageDocs.Add(single);
}
// Merge the single-page docs into one ordered document
using var merged = PdfDocument.Merge(pageDocs.ToArray());
// Save the new ordered PDF
merged.SaveAs("report-reorganized.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output PDF Document

How to Rearrange Pages in PDF C# With IronPDF: Image 2 - Output for first example of how to rearrange pages in PDF C#

The CopyPages method accepts an IEnumerable<int> containing int pageIndex values that match your desired arrangement. This approach lets you rearrange PDF pages, duplicate specific pages, or extract several pages into a separate document. The method returns a new PdfDocument class object, leaving the original source document unchanged.

For developers working in Java environments, IronPDF is also available for Java, with similar page-manipulation functions and API structure.

How Can Multiple Pages Be Rearranged at Once?

When working with PDF documents containing multiple pages, you can rearrange the entire document structure in a single operation. The following code shows how to reverse all pages in a PDF or create any custom page sequence.

using IronPdf;
// Load PDF document with several pages
var doc = PdfDocument.FromFile(@"C:\Users\kyess\Desktop\Desktop\Code-Projects\Assets\quarterly-report.pdf");
int count = doc.PageCount;
// Build reversed single-page PDFs
var pages = new List<PdfDocument>();
for (int i = count - 1; i >= 0; i--)
{
    // Copy a single page as a standalone PDF
    pages.Add(doc.CopyPage(i));
}
// Merge all the reversed single-page PDFs
using var reversed = PdfDocument.Merge(pages.ToArray());
// Save to a NEW filename (avoids viewer caching)
reversed.SaveAs("manual-reversed-final_1.pdf");
using IronPdf;
// Load PDF document with several pages
var doc = PdfDocument.FromFile(@"C:\Users\kyess\Desktop\Desktop\Code-Projects\Assets\quarterly-report.pdf");
int count = doc.PageCount;
// Build reversed single-page PDFs
var pages = new List<PdfDocument>();
for (int i = count - 1; i >= 0; i--)
{
    // Copy a single page as a standalone PDF
    pages.Add(doc.CopyPage(i));
}
// Merge all the reversed single-page PDFs
using var reversed = PdfDocument.Merge(pages.ToArray());
// Save to a NEW filename (avoids viewer caching)
reversed.SaveAs("manual-reversed-final_1.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Reversed PDF Pages Output

How to Rearrange Pages in PDF C# With IronPDF: Image 3 - PDF with reversed pages so the conclusion is at the start

This code loads a PDF file, determines the page number count, and constructs an array to reverse the page sequence. The var page references within the loop dynamically build the new order, making this approach scalable for documents with any number of pages in a PDF.

You can also swap just two pages by specifying their positions. For instance, to swap pages 0 and 2 while keeping page 1 in place, use new int[] { 2, 1, 0 } as your index array. Visit the IronPDF page manipulation documentation for additional examples.

How to Move a Page to a New Location?

Moving a single page to a different location requires combining copy and insert operations. The InsertPdf method allows precise placement of pages at any index within the document structure.

using IronPdf;
// Load the input PDF file
var pdf = PdfDocument.FromFile("presentation.pdf");
int sourceIndex = 1;   // page you want to move
int targetIndex = 3;   // new location
// Make sure indexes stay valid after removal
bool movingForward = targetIndex > sourceIndex;
// 1. Copy the page you want to move (creates a 1-page PdfDocument)
var pageDoc = pdf.CopyPage(sourceIndex);
// 2. Remove the original page
pdf.RemovePage(sourceIndex);
// 3. If moving forward in the document, target index shifts by -1
if (movingForward)
    targetIndex--;
// 4. Insert the copied page
pdf.InsertPdf(pageDoc, targetIndex);
// Save final result
pdf.SaveAs("presentation-reordered.pdf");
using IronPdf;
// Load the input PDF file
var pdf = PdfDocument.FromFile("presentation.pdf");
int sourceIndex = 1;   // page you want to move
int targetIndex = 3;   // new location
// Make sure indexes stay valid after removal
bool movingForward = targetIndex > sourceIndex;
// 1. Copy the page you want to move (creates a 1-page PdfDocument)
var pageDoc = pdf.CopyPage(sourceIndex);
// 2. Remove the original page
pdf.RemovePage(sourceIndex);
// 3. If moving forward in the document, target index shifts by -1
if (movingForward)
    targetIndex--;
// 4. Insert the copied page
pdf.InsertPdf(pageDoc, targetIndex);
// Save final result
pdf.SaveAs("presentation-reordered.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Original PDF vs. The Output

How to Rearrange Pages in PDF C# With IronPDF: Image 4 - Comparison of the input PDF vs. the output PDF with the moved page

This process extracts a page using CopyPage, removes it from the source document with RemovePage, then inserts it at the target location, before saving the new PDF with the new file name. The page index values shift after removal, so plan your operations accordingly. This method works well when you need to move specific pages without reconstructing the entire document.

How to Delete and Reorder Pages Using MemoryStream?

For applications that automate PDF processing without writing intermediate files to disk, working with byte arrays and memory streams provides better performance. The following code demonstrates how to load, manipulate, and save PDF pages entirely in memory.

using IronPdf;
using System.IO;
// Load PDF from byte array (simulating input from database or API)
byte[] pdfBytes = File.ReadAllBytes("report-with-blank.pdf");
var pdf = new PdfDocument(pdfBytes);
// Delete blank page at index 2
pdf.RemovePage(2);
// Reorder remaining pages: create new sequence
var reorderedPdf = pdf.CopyPages(new int[] { 1, 0, 2, 3 });
// Export to MemoryStream for further processing
MemoryStream outputStream = reorderedPdf.Stream;
// Or save directly with new MemoryStream pattern
File.WriteAllBytes("cleaned-report.pdf", reorderedPdf.BinaryData);
using IronPdf;
using System.IO;
// Load PDF from byte array (simulating input from database or API)
byte[] pdfBytes = File.ReadAllBytes("report-with-blank.pdf");
var pdf = new PdfDocument(pdfBytes);
// Delete blank page at index 2
pdf.RemovePage(2);
// Reorder remaining pages: create new sequence
var reorderedPdf = pdf.CopyPages(new int[] { 1, 0, 2, 3 });
// Export to MemoryStream for further processing
MemoryStream outputStream = reorderedPdf.Stream;
// Or save directly with new MemoryStream pattern
File.WriteAllBytes("cleaned-report.pdf", reorderedPdf.BinaryData);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

The PdfDocument class object accepts byte array input, and the Stream property returns the PDF as a MemoryStream. This approach suits web applications, cloud environment deployments, and scenarios where you need to manipulate PDF documents without file system access. The library handles memory management efficiently even when processing large documents.

Refer to the API references for PdfDocument to explore additional methods for page operations, including rotation, extraction, and merging.

Conclusion

This article covered essential techniques for rearranging pages in C# using IronPDF: reordering pages with index arrays, moving pages to new locations, deleting unwanted content, and processing documents in memory. The library's intuitive API lets you automate complex PDF page operations with minimal code.

Download IronPDF to begin testing these features in your .NET environment by trying the free trial to evaluate the full capabilities. For production deployments requiring advanced PDF manipulation, explore licensing options that match your project requirements. Want to learn more? Check out our help resources, including our blog posts and extensive documentation that demonstrate how each of IronPDF's powerful features works.

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