Remove Blank PDF Pages using Java

This quick guide explains the process to remove blank PDF pages using Java. It has settings for the IDE, a list of steps, and a sample code showing how to delete blank page in PDF using Java. A few enhancements will also be discussed to generate custom output.

Steps to Delete Blank Page from PDF using Java

  1. Set the IDE to add Aspose.PDF for Java to remove empty pages from a PDF
  2. Load the license to utilize full product features
  3. Load the source PDF file into the Document class object with blank pages in it
  4. Parse through each page and check if it is empty or not
  5. Verify that the page should not have text, images, annotations, and forms
  6. Create a list of blank pages by checking all the pages in the PDF
  7. Delete all the pages marked as blank during the above-mentioned steps
  8. Save the resultant PDF file after removing the empty pages

These steps describe how to remove blank page in PDF using Java. Load the product license, load the source PDF file, parse through each page in the PDF, and check if any text, image, annotation, or embedded form is present on the page. Generate a list of blank pages, delete them from the PDF, and save the resultant output PDF file.

Code to Delete Extra Page in PDF using Java

This code demonstrates how to remove extra page in PDF using Java. You can use the Document.OptimizeResources() to remove the unused objects after deleting the blank pages. The manual reverse loop can be avoided by using the Pages.Delete(int[]) method, which removes all marked blank pages in a single call.

This article assists in deleting extra or blank pages from a PDF file. To change a colored PDF file to a black and white PDF file, refer to the article Change PDF to Black and White using Java.