How to Rearrange Pages in PDF C# With IronPDF

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");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");Output PDF Document

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");Reversed PDF Pages Output

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");Original PDF vs. The Output

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);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.
Frequently Asked Questions
How can I rearrange PDF pages in C# using IronPDF?
You can rearrange PDF pages in C# using IronPDF by following step-by-step code examples that guide you through reordering, copying, and deleting pages in PDF documents programmatically.
What are the benefits of using IronPDF for manipulating PDF pages?
IronPDF provides a robust and flexible API for manipulating PDF pages, allowing developers to efficiently reorder, copy, and delete pages with ease, enhancing productivity and reducing development time.
Is it possible to delete specific pages in a PDF using IronPDF?
Yes, IronPDF allows you to programmatically delete specific pages from a PDF document using C# code, which can be particularly useful for document management and customization.
Can I copy pages from one PDF to another using IronPDF?
IronPDF supports copying pages from one PDF to another, enabling you to merge documents or duplicate sections as needed within your C# applications.
What code examples are available to help with PDF page manipulation in C#?
The web page provides step-by-step code examples that demonstrate how to reorder, copy, and delete PDF pages using IronPDF, making it easier for developers to implement these features.
Does IronPDF support reordering multiple pages at once?
Yes, IronPDF allows you to reorder multiple pages at once, providing efficient methods to rearrange large documents without having to manipulate each page individually.









