I need to automatically reduce the size of some user uploaded pdfs so that they can be sent via email.
I have a little imagemagick oneliner that reduces the size for me:
convert -density 120 -quality 10 -compress jpeg original.pdf output.pdf
basically exports every page of the pdf in jpg, updates density and quality and repacks the pages in a new PDF.
this works perfectly, except that with this command sometimes the files end up bigger, and I need to rerun tweaking density and quality to get the lowest size where the text in the pdf documents is still readable.
I'm not sure how to automate it. I thought to use identify to get characteristics of the files (height width density... ) and do stuff like half the figures or sth similar. but I'm struggling to get this info about the files.
Any suggestions?
Thanks,
-compress jpg
(and perhaps even the-quality 10
) directives are dispensable. – Zerk--compress LZW
or--compress lzw
, that is better for color pages – Stetson-compress jpg
directive is absolutely necessary to achieve the goal: Lossy jpeg -recompression with tweaked resolution and quality parameters! Without this parameter the image format of the processed image assets within the PDF will be changed to an uncompressed bitmap image and only the-density
parameters has an effect. Downsampling takes place, but no lossy image compression. An inspection withpdfimages -list
of the different variants proofed this. – Altazimuth-quality XX
, try-define jpeg:extent={size}
, where size is specified with a suffix. For example "400kb". – Preciosa