This basic tutorial provides the details on how to split PDF file by pages in C#. By following the steps and the code snippet in C# split PDF into multiple files using a few lines of code. Moreover, you can customize the splitting process by filtering the page number or performing a variety of operations before creating a separate document out of it.
Steps to Split PDF File by Pages in C#
- Add the reference to Aspose.PDF for .NET library in the application for splitting the PDF pages
- Load the input PDF file for splitting using the Document class
- Iterate through each page of the input PDF file using the Page class
- Write each page to a separate PDF document with the Save method
These steps simply explain how using C# split PDF into pages operation can be performed. Quickly configure the library and then load the input document for processing it. Iterate through each page one by one and save it as a separate file along with the option to rotate, add some header/footer, add watermark, crop the page, and a lot of other customizations too.
Code to Split PDF File by Pages in C#
For writing an application to split PDF pages C# code is demonstrated here. Before adding each page to a new PDF file, you can use all Page class features like you can change the page size, adding some background, stamping the page with image or text, setting page color, and so on. Similarly, after adding the page to a new PDF file, you can use Document class features like formatting it by embedding fonts into it, setting its expiry date, optimizing the PDF file by removing unused objects, compressing images, and modifying the contents in a variety of ways.
In this article, we have learned how using C# split PDF into pages functionality can be embedded into your .NET or .NET Core framework-based applications. Similarly, if you want to learn the merging of PDF pages, refer to the article on how to merge PDF files using C#.