Hello!
I convert pdf-documents to PDF/A this way:
Document document = new Document(new ByteArrayInputStream(this.sourceContent)); boolean optimize = true; PdfFormatConversionOptions options = new PdfFormatConversionOptions(PdfFormat.PDF_A_1A, ConvertErrorAction.Delete); options.setOptimizeFileSize(optimize); document.convert(options); if (optimize) { OptimizationOptions opt = new OptimizationOptions(); opt.setRemoveUnusedObjects(true); opt.setRemoveUnusedStreams(true); opt.setLinkDuplcateStreams(true); opt.setSubsetFonts(true); document.optimizeResources(opt); } document.save("output.pdf");
Without optimization, the resulting pdf (output.pdf) becomes way too big (1825 KB).
The adobe acrobat memory check shows, that the overhead comes from embedded fonts.
Tests showed, that setting setOptimizeFileSize(true) during conversion to PDF/A is not enough to reduce the file size, in contrast to the detailed explanation in Aspose Pdf uses two ways to optimize PDF file size - #12 by asad.ali . But why?
With additional optimization (document.optimizeResources) enabled as shown above, the size of the resulting pdf (outputOptimized.pdf) is fine (93 KB), but some document content is lost (in this example the page number at the end of page 2 is lost).
Is there a way to convert and optimize this document without losing content?
Attached is a zip with the input.pdf (405 KB) and the two output-pdfs: optimize.zip (2.2 MB)