Spire.PDF allows us to rearrange the pages in an existing PDF document by using the Rearrange(int[] orderArray) method. This article explains how we can use Spire.PDF to implement this function.
Below is the screenshot of the source PDF document:
Refer to below detail steps:
Step 1: Load the existing PDF document.
PdfDocument doc = new PdfDocument("New Zealand.pdf");
Step 2: Rearrange pages by page index.
doc.Pages.ReArrange(new int[] { 2, 1, 0 });
Step 3: Save and close the document.
doc.SaveToFile("Output.pdf"); doc.Close();
Screenshot after rearranging pages:
Full code:
using Spire.Pdf; namespace Rearrange_page_in_PDF { class Program { static void Main(string[] args) { //Load the PDF document PdfDocument doc = new PdfDocument("New Zealand.pdf"); //Rearrange pages by page index doc.Pages.ReArrange(new int[] { 2, 1, 0 }); //Save and close the document doc.SaveToFile("Output.pdf"); doc.Close(); } } }