4

How can you increase the JPEG compression level on a PDF using batch tools under Linux?

Obviously you can use gs -dPDFSETTINGS=/screen or /ebook, but that downsamples the PDF - it reduces the DPI. It's more efficient (in terms of how nice the PDF looks per KB) to use JPEG compression while retaining the same pixel count.

E.g.: https://docupub.com/pdfcompress/ allows you to half the size of a PDF yet when you zoom in it still has good quality, albeit with some artifacts. When you zoom in using gs's /ebook mode, it inevitably looks more pixelated.

What Linux tool allows us to apply JPEG compression to each image in a PDF?

Is there any way to use ImageMagick's convert -quality on a PDF of multiple images?

2 Answers 2

0

AS per comment here: How can you compress images in a PDF (via a GUI, not batch or CLI util)?

you can try

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dColorImageResolution=230 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed-output.pdf input.pdf

Tweak the dColorImageResolution variable - I could shove of about one third from the size of my PDF (but for degraded image quality, as expected).

-2

ImageMagick's built-in convert can operate on PDFs:

convert -density 300 input.pdf -quality 30 output.pdf

Unfortunately quality does not seem to be recognized when adding other arguments such as threshold and fails to compress PDFs created by ImageMagick, e.g.:

convert -density 300 input.pdf -threshold 60% - | convert - -quality 30 output.pdf

fails - it produces three copies of each old page on each new page.

If you know how to work around this, please let me know.

1
  • 1
    convert essentially turns the entire PDF into a single JPEG image, embedded into a PDF. I don't think that's what the question asker wanted to do.
    – apdnu
    Commented Mar 4, 2023 at 16:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .