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
- Set the IDE to use Aspose.PDF for Java to remove metadata
- Load the target PDF file using the Document class object for stripping metadata
- Fetch the document metadata using the DocumentInfo class object
- Call the clear() method to delete default metadata
- Use the clearCustomData() method to remove custom metadata if any
- 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.