In this digital era, PDF is one of the most used file formats and is popular due to its portability. On the other hand, most of the time we can not edit the PDF files. When we merge multiple documents and pages together to form a combined comprehensive document, it often happens that we finish combining the pages in the wrong order. This article discusses, how to rearrange PDF pages programmatically using C#.
.NET API to Rearrange PDF Pages & Merge Documents
In order to rearrange pages in documents, GroupDocs provides GroupDocs.Merger for .NET. The API enables removing, splitting, and extraction of pages, changes in page orientation, and rotation of document pages within .NET applications. For the details and other features of the API, you can visit the documentation.
PM> Install-Package GroupDocs.Merger
Rearrange PDF Pages using C#
The following are the steps that reorder the pages of PDF documents using C#.
- Define the existing and new position of the page in MoveOptions class.
- Load the PDF document using the Merger class.
- Use MovePage() method to reorder according to defined options.
- Save the PDF file with the new page order using the Save() method.
The following C# code rearranges the pages of PDF documents. Precisely, it moves the 6th page of the document to the 1st place.
Here is the output of the above code.
Get a Free API License
You can get a free temporary license in order to use the API without the evaluation limitations.
To conclude, we learned how to reorder pages of the PDF files using C# within the .NET applications. We saw the running example to change the position of the page. You can try building a simple application that can organize the PDF files by easily shuffling their pages.