Delete Attachments from the PDF Document

Hi,

i need to remove the attachments from a pdf to reduce the original size, but it seems not work well.

The new file is without attachment, but with the same size of the original with attachment.

Thank in advance,

Marco

Hi Marco,


Thanks for using our API’s.

Once the attachments are removed, please try using Document.optimizeResources(…) method to compress the PDF file. Please try using following code snippet.

[Java]

com.aspose.pdf.facades.PdfContentEditor
editor =
new
com.aspose.pdf.facades.PdfContentEditor();<o:p></o:p>

editor.bindPdf("c:/pdftest/12422.pdf");

editor.deleteAttachments();

editor.save("c:/pdftest/ContentEditor.pdf");

Document originalDocument = new Document("c:/pdftest/ContentEditor.pdf");

com.aspose.pdf.Document.OptimizationOptions optimize = new com.aspose.pdf.Document.OptimizationOptions();

optimize.setCompressImages(true);

optimize.setRemoveUnusedObjects(true);

optimize.setRemoveUnusedStreams(true);

optimize.setUnembedFonts(true);

optimize.setLinkDuplcateStreams(true);

originalDocument.optimizeResources(optimize);

originalDocument.save("c:/pdftest/FileOptimized.pdf");

It works perfectly.

Thank you very much!

Hi Marco,


Thanks for your feedback. It is good to know that your issues has been resolved.

Please keep using our API and feel free to ask any question or concern, we will be more than happy to extend our support.

Best Regards,