How to Save Selected Pages in PDF using C#

This article explains how to save selected pages in PDF using C#. It provides the configuration details, a set of steps, and a runnable sample code to save only selected pages from PDF using C#. You will also learn different options to extract one or more pages as per the application requirements.

Steps to Save Selected Pages of PDF using C#

  1. Set the environment to use Aspose.PDF for .NET to select and save the pages
  2. Create an array of page indexes required to be extracted and saved separately
  3. Declare an object of PdfFileEditor using the constructor without any arguments
  4. Use the PdfFileEditor.Extract() method by providing the source PDF, list of pages, and resultant PDF file name

All the necessary tasks are summarized here explaining how to save selected pages from PDF using C#. In the first step, a discrete or continuous list of page numbers is stored in an array followed by the creation of a PdfFileEditor class object having different overloaded methods to extract desired pages from the source PDF file. In the final step, the Extract() method is called with the necessary inputs that generate the resultant PDF file at the end.

Code to Save Selected Pages from PDF using C#

This code demonstrates how to save selected page in PDF using C#. It uses the PdfFileEditor class from the Aspose.Pdf.Facades namespace that has a large number of features to work with PDF files for instance splitting files from start, end, or based on pages, making N-up documents and saving them on disk, streaming or a HttpResponse, concatenating multiple PDF files, appending pages to an existing PDF file, and add margins/page breaks to a PDF file. Pages can be extracted by providing a selected page index or providing a range of page numbers based on application requirements.

This article has taught us to save the selected pages in a PDF, however, if you want to learn the process to rearrange the pages in a PDF, refer to the article on how to rearrange pages in a PDF using C#.

 English