Jacob Collins Jacob is a Java developer and the product manager of JPedal

How to remove unused objects from a PDF file (Tutorial)

36 sec read

How to view pdf metadata using Java (PDF logo)

PDF files sometimes contain objects which are never used. This increases the file size and is wasteful. This tutorial shows you how to reduce the file size by removing these unused objects in Java or using the command line.
 
The PDF file format is not natively supported by Java, so to remove unused objects from a PDF file you will need to download an external library. This tutorial uses JPedal.
 

How to remove unwanted objects from a PDF file programmatically

  1. Add JPedal to your class or module path (download the trial jar)
  2. Create a File handle pointing to the PDF file
  3. Run the below code:

 

How to remove unwanted objects from a PDF file using the command line

  1. Download the JPedal trial jar
  2. Run the following command:
    java -cp jpedal.jar org.jpedal.tools.PdfOptimizer --removeUnusedObjects inputFile outputFile




The JPedal PDF library allows you to solve these problems in Java


Why do developers choose JPedal over alternatives?

  1. Actively developed commercial library with full support and no third party dependencies.
  2. Simple licensing options and source code access for OEM users.
  3. Process PDF files up to 3x faster than alternative Java PDF libraries.

Jacob Collins Jacob is a Java developer and the product manager of JPedal