Get a site

Compress pdf files via CLI

After scanning lot of pages into a single pdf file, there could be the problem of the file dimension. To compress pdf file, you can use Ghostscript via CLI.

The complete command is:

gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/screen -sOutputFile=new_file.pdf original_file.pdf

Analizing option at a time:

  • -dNOPAUSE:
    Disables the prompt pause at the end of each page.
  • -dBATCH:
    Exit after last page.
  • -sDEVICE:
    To specifiy the output device (in this case the pdfwrite, the command gs --help shows all possible devices).
    To choose the compression level

    • /screen: selects low-resolution output, and the lowest file-size.
    • /ebook: selects medium-resolution output, with a medium file-size.
    • /printer or /prepress: are both for the high-resolution options.
  • -sOutputFile:
    Selects an alternative output file.

Published by Francesco Serafin

I am a PhD student at the Department of Civil, Environmental and Mechanical Engineering at the University of Trento. My two greatest loves: Computer Science and Water (take three with my Lenovo!:D). As a result, the aim of my life is to make both passions coexist. My gpg public key available at

Leave a Reply

Your email address will not be published.

%d bloggers like this: