How to Remove Metadata from PDF in Java

This short tutorial guides how to remove metadata from PDF in Java. It has the reference to the required resources for running the application, a list of programming steps, and a runnable sample code to strip PDF metadata in Java. You will exercise methods to remove default or custom metadata separately if required.

Steps to Clean Metadata from PDF in Java

  1. Set the IDE to use Aspose.PDF for Java to remove metadata
  2. Load the target PDF file using the Document class object for stripping metadata
  3. Fetch the document metadata using the DocumentInfo class object
  4. Call the clear() method to delete default metadata
  5. Use the clearCustomData() method to remove custom metadata if any
  6. Save the output PDF file after removing the metadata

These steps summarize the process to delete PDF metadata in Java. First, the source PDF file is loaded and its metadata is extracted. Next, the clear() and clearCustomData() methods are called to clear the metadata.

Code to Erase Metadata PDF in Java

This sample code demonstrates how to clean PDF metadata in Java. It demonstrates the built-in methods to remove default and custom properties using the clear() and clearCustomData() methods respectively. If you want to remove the selected metadata only, you may clear the desired properties in the DocumentInfo object or call the remove() or removeItemByKey() methods in the DocumentInfo class if required.

This sample code demonstrates the process to remove metadata from PDF in Java. If you want to remove watermarks from a PDF, refer to the article on how to remove watermark from PDF file in Java.

 English