Remove Blank PDF Pages using Python

This tutorial explains how to remove blank PDF pages using Python. It contains information to configure the development environment, a list of steps, and sample code to delete extra pages from PDF using Python. Various options will be discussed to enhance the code for custom output.

Steps to Delete Blank Page from PDF using Python

  1. Establish the development environment for using Aspose.PDF for Python via .NET
  2. Load the license to use the product without any trial limitations
  3. Load the source PDF file into the Document object and parse through each page
  4. Check that no content is present on the page, such as text, image, annotation, or forms
  5. Prepare a list of blank pages using the above criteria
  6. Parse through each page in reverse order and delete the blank pages
  7. Save the output PDF file after deleting the empty pages

The above steps show how to remove blank page in PDF using Python. To commence the process, load the license, load the source PDF file with blank pages in it, check the presence of any type of content on each page and prepare a list of blank pages. Finally, parse the PDF file in reverse order, delete the blank pages from the list, and save the resultant PDF file.

Code to Delete Extra Page in PDF using Python

The above-mentioned code demonstrates how to delete blank page in PDF using Python. There is an option to delete all the pages at once using a single call to Pages.Delete(int[]) instead of deleting pages one-by-one. To detect images which are actually rendered on a page, use the ImagePlacementAbsorber instead of Resources.Images.Count.

This article teaches the process to remove blank pages. To transform a colored PDF to a black-and-white PDF, refer to the article Change PDF to Black and White using Python.

 English