This quick tutorial explains how to delete PDF pages in C#. It shares the details to set the environment, a set of tasks to be performed in the application, and a runnable sample code demonstrating how to delete pages from PDF in C#. This sample code can be executed in any of the platforms supporting .NET framework and more options will also be explored to delete pages in different ways.
Steps to Remove Pages from PDF in C#
- Set the IDE to use Aspose.PDF for .NET to delete pages
- Create a PdfFileEditor instance from the Aspose.Pdf.Facades namespace for removing the pages
- Create an array of integers having a list of page numbers to be removed from the target PDF
- Call the Delete() method providing the input file, list of pages to remove, and the output PDF file
These steps summarize how to remove pages from PDF in C#. The process is commenced by instantiating an object of the PdfFileEditor class that has rich features to remove pages from a PDF. It requires the source PDF file name, an array of integers depicting the page numbers to be deleted, and the output PDF file name after deleting the pages.
Code to Remove Pages from PDF Document in C#
The above code demonstrates how to remove some pages from PDF in C#. You can use a stream as a source PDF file name and save the resultant PDF file into a stream instead of a file on the disk. Similarly, the resultant PDF file can be saved to an HttpResponse object also if required.
This article has taught us to delete pages from PDF document in C#. If you want to learn the process of removing hyperlinks from a PDF file, refer to the article on how to remove hyperlink from PDF in C#.