Qoppa’s 100% Java PDF optimizer library, jPDFOptimizer, allows, among other things, to remove unnecessary objects in a PDF document in order to reduce the file size.
This is done using the OptSettings class.
OptSettings options = new OptSettings(); // Options to remove objects options.setDiscardAltImages(true); options.setDiscardAnnotations(true); options.setDiscardBookmarks(true); options.setDiscardDocumentInfo(true); options.setDiscardFileAttachments(true); options.setDiscardFormFields(true); options.setDiscardJSActions(true); options.setDiscardLinks(true); options.setDiscardPageThumbnails(true); options.setDiscardUnusedResources(true); options.setDiscardXMPData(true); |
Method | Description |
Alternate Images
OptSettings.discardAltImages() |
Removes alternate embedded image dictionaries that are used for high resolution printing to reduce file size. Only visible images displayed on the PDF while viewing will be kept in the document. |
Bookmarks
OptSettings.discardBookmarks() |
Removes all bookmarks from the PDF document |
Document Info
OptSettings.setDiscardDocumentInfo() |
Removes any document information located in the document properties (Document->Document Properties) that would include the following:
|
JavaScript Actions
OptSettings.setJSActions() |
This will remove all JavaScript actions from the PDF document but retain any objects that may have had JavaScript actions such as form fields, push buttons, etc… |
Embedded Thumbnails
OptSettings.setDiscardPageThumbnails() |
Removes page thumbnails that are stored in the PDF document. Once removed the page thumbnails will just be rendered each time the document is loaded. |
Comments
OptSettings.setDiscardComments() |
Removes all annotations and comments from the PDF document |
Links
OptSettings.setDiscardLinks() |
Removes all links from the PDF document |
Attachments
OptSettings.setDiscardFileAttachments() |
Removes any attachments that are stored within the document |
Form Fields
OptSettings.setDiscardFormFields() |
Removes all form fields that are on the PDF document |
Metadata
OptSettings.setDiscardXMPData() |
Removes all additional or extra Metadata from the PDF Document |
Unused Resources
OptSettings.setDiscardUnusedResources() |
Removes resources that are located within the document but are never referenced by any objects in the PDF document. |