Skip to content

Instantly share code, notes, and snippets.

@fartinmartin
Last active October 31, 2025 22:01
Show Gist options
  • Select an option

  • Save fartinmartin/a954f6e9dbbf391bd9cfb31cb3c09b72 to your computer and use it in GitHub Desktop.

Select an option

Save fartinmartin/a954f6e9dbbf391bd9cfb31cb3c09b72 to your computer and use it in GitHub Desktop.
PDF optimization via CLI

PDF optimization via CLI

  • Open a new Terminal.app window
  • Type cd (including the space)
  • Drag and drop folder containing original PDFs into the terminal window. Now the command looks something like:
cd /Users/work/Desktop/My\ PDFs 
  • Press Enter

Tip

You can comfirm you're in the correct folder by typing ls and pressing enter. This will display the files in the folder you're working in.

  • Copy the example Ghostscript command:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dBATCH \
   -sOutputFile=small.pdf original.pdf
  • Replace original.pdf with the name of the pdf you want to compress, for example:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dBATCH \
   -sOutputFile=small.pdf Newsletter.pdf

Important

Remember that filenames with spaces need to be wrapped in quotes. E.g. "My Cool Newsletter.pdf" (good) instead of My Cool Newsletter.pdf (bad).

  • Press enter and you're done, yay! The command has created a small.pdf file inside the folder containing the original PDFs that you drag and dropped at the start of this process.

Important

Rembmer to rename the small.pdf file that the example command creates. Otherwise you might overwrite it when running this command again with a different PDF file. Alternatively, read the tip below:

Tip

If you want, you can rename the output file when running the command:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dBATCH \
   -sOutputFile="My Cool Newsletter SMALL.pdf" "My Cool Newsletter.pdf"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment