The convert() method complains about compressed images. However, our customer has a PDF tool (PDF-XChange Editor) that keeps the document size. Sometimes the size factor is up to 10.
I’ve tried the optimize function, no improvement.
Is there only a way out, to reduce the resolution?
A sample PDF and result is attached (original 3mb, pdf/a 7mb).
Here is the Code:
public static void main( String[] args ) throws Exception {
new License().setLicense( "Aspose.Total.Java.lic" );
String infile = "test-shading.pdf";
String outfile = "test-shading-pdf2a.pdf";
System.out.println( "file size: " + Files.size( Path.of( infile ) ) );
Document doc = new Document( infile );
OptimizationOptions opt = new OptimizationOptions();
opt.getImageCompressionOptions().setCompressImages( true );
doc.optimizeResources(opt);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
boolean ok = doc.convert( baos, PdfFormat.PDF_A_2A, ConvertErrorAction.Delete );
if ( baos.size() > 0 ) {
String warn = baos.toString( StandardCharsets.UTF_8 );
System.out.println( warn );
}
if ( !ok ) {
System.out.println( "error convert" );
System.exit( 1 );
}
doc.optimizeResources();
doc.save( outfile );
System.out.println( "outfile size: " + Files.size( Path.of( outfile ) ) );
}
test-shading.zip (1.9 MB)