EigenFunctions has asked for the wisdom of the Perl Monks concerning the following question:

I am creating a PDF file by concatenating many PNG files, each of which are small (50k, or so each). However, the resultant PDF is huge (on the order of 13MB).

Is there a way to compress the PDF into a smaller file?

I am using API2 v2.15, Perl V5.10.0, Win/xp sp2

Thanks,

EigenFunctions

Replies are listed 'Best First'.
Re: API2 PDF Compression
by almut (Canon) on Jun 09, 2010 at 14:53 UTC

    Please don't put the actual content of your node in the signature.

    As for the growth in size (assuming you mean that the resultant PDF file is significantly larger than what you would expect from simply adding their individual sizes), the problem might be that the compression algorithm used by PNG files is not natively supported by PDF, so the image data needs to be re-encoded in some suboptimal format (AFAICT, the DEFLATE algorithm is being applied by PDF::API2). Although PNG compression also involves a DEFLATE step, various pre-compressions are used, which are not supported by PDF.

    OTOH, PDF natively supports DCT compression, as used for JPG files (i.e. they can be embedded as is), so my (untested) suggestion would be to try converting your files to JPG format before putting them in the PDF — in case you can live with the fact that JPG compression is lossy (lossyness can be controlled by the quality factor).