The JPedal Java PDF library can remove blank pages from documents.
Rationale
But why might you want to do this? A common reason would be for saving paper when printing documents. Or perhaps you want to remove empty gaps from a presentation.
How to remove blank pages using Java
Since Java does not provide any native ways to interact with PDF files, you will need a PDF library. We have been developing JPedal for over 20 years and it contains a powerful PDF Manipulator.
Using the following code, we can scan the whole document and write out a version of it that does not contain any blank pages.
final PdfManipulator pdf = new PdfManipulator();
pdf.loadDocument(new File("inputFile.pdf"));
pdf.removeBlankPages();
pdf.apply();
pdf.writeDocument(new File("outputFile.pdf"));
pdf.closeDocument();
pdf.reset();
Download JPedal
You can download a JPedal trial jar to see you it works.
Resources
Learn more about manipulating PDF files in Java.
We can help you better understand the PDF format as developers who have been working with the format for more than 2 decades!