This article describes the process to remove blank PDF pages using C#. You will get details to set the IDE, a list of steps, and sample code demonstrating how to delete blank page in PDF using C#. Various enhancements will be discussed to improve the sample code for creating custom output.
Steps to Delete Extra Page in PDF using C#
- Set the IDE to use Aspose.PDF for .NET to remove blank pages
- Apply a valid license to avail complete product features
- Load the source PDF file using the Document class
- Parse through each page in the loaded PDF file
- Verify that the current page has no text, images, annotations, and embedded forms
- Mark each blank page using the above criteria
- Parse through each page from the last page and delete all the blank pages
- Save the updated PDF file without the empty pages
These steps summarize the process of how to remove blank page in PDF using C#. Load the source PDF into the Document object, parse through each page and check if it contains text, images, annotations, or embedded forms, and save the list of blank pages. Finally, delete all blank pages from the last page and save the resultant output PDF file.
Code to Delete Blank Page from PDF using C#
This code demonstrates how to delete extra pages from PDF using C#. You may try the Pages.Delete(int[]) to delete all the blank pages using one call instead of iterating through all pages while deleting the blank pages. The ImagePlacementAbsorber can be used to detect the presence of only those images that are rendered on the page as Resources.Images.Count includes referenced resources also.
This short tutorial teaches the process to search the blank pages and then delete all of them from the PDF file. To change a PDF to a black and white PDF, refer to the article Change PDF to Black and White using C#.