How to Rearrange Pages in a PDF using C#

This how-to guide assists in how to rearrange pages in a PDF using C#. It contains detailed instructions to move pages at different positions within the PDF document along with the runnable sample code to change the order of pages in pdf using C#. You will learn different options to rearrange the pages like inserting a page at the end of the document or inserting it at a particular index as per the requirements.

Steps to Change Order of Pages in PDF using C#

  1. Set the environment to use Aspose.PDF for .NET for rearranging the pages
  2. Initialize a new Document object and add a few pages along with inserting some sample text
  3. Move a page to the end of the document
  4. Save the intermediate file to see the result
  5. Move a page between some existing pages
  6. Save the resultant PDF file with reordered pages

These steps summarize the process of how to change the order of pages in PDF using C# within the same PDF file. Once the PDF file with multiple pages is loaded or created, the pages are moved to the end of the file or inserted at a particular index in the pages collection of the PDF file. The intermediate files are saved at different stages to observe the output at the specified step.

Code to Move PDF Pages using C#

This sample code demonstrates the process to reorder pages in a PDF using C#. For moving the page to the end of the document the target page is added to the collection of the pages and finally, the source page is deleted. Similar logic is used to insert a page at a particular index such that first the reference to the target page is accessed and then the Insert() method is called to insert the page before deleting the source page.

This article has taught us how to move pages in PDF using C#. If you want to learn the process to merge PDF files, refer to the article on how to merge PDF files using C#.

 English