Search code examples
compressionpdftk

pdftk compression option


I use pdftk to compress a pdf using the following command line

pdftk file1.pdf output file2.pdf compress

It works as the weight of my file decreased.

Are there [options] to change the compression???

Or maybe other solutions to compress my file? It is heavy because some graphics have a lot of points. Is there a way to convert these graphs to jpg for instance and adapt the compression?


Solution

  • I had the same problem and found two different solutions (see this thread for more details). Both reduced the size of my uncompressed PDF dramatically.

    • Pixelated (lossy):

      convert input.pdf -compress Zip output.pdf
      
    • Unpixelated (lossless, but may display slightly differently):

      gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dBATCH  -dQUIET -sOutputFile=output.pdf input.pdf
      

    Edit: I just discovered another option (for lossless compression), which avoids the nasty gs command. qpdf is a neat tool that converts PDFs (compression/decompression, encryption/decryption), and is much faster than the gs command:

    qpdf --linearize input.pdf output.pdf