JPedal provides a PdfManipulator class which includes several document sanitization features.
To get started, use the following code snippet:
final PdfManipulator pdf = new PdfManipulator();
pdf.loadDocument(new File("inputFile.pdf"));
// Now choose one or more of the below options to insert here
pdf.apply();
pdf.writeDocument(new File("outputFile.pdf"));
pdf.closeDocument();
pdf.reset();
Remove JavaScript
The PDF Manipulator provides the following methods for detecting and removing the presence of JavaScript in PDF files.
boolean containsJS = pdf.containsJavaScript();
pdf.removeJavaScript();
You do not need to call
containsJavaScript()
in order to callremoveJavaScript()
Remove Metadata
The PDF Manipulator provides the following method for removing metadata from PDF files.
pdf.removeMetadata();
Remove Embedded Files
The PDF Manipulator provides the following method for removing embedded/attached files from PDF files.
pdf.removeEmbeddedFiles();
Learn more about the PdfManipulator.