Reduce PDF File Size With Ghostscript

Reduce PDF File Size With Ghostscript

I’m going to be honest. I don’t worry too much about PDF file size. Storage (both local and online) is relatively cheap. However, sometimes people will ask me how to reduce PDF file size, so it’s clearly a topic of interest.

There are many solutions out there, but over on the Asian Efficiency Dojo, user Andrew pointed me to this AskUbuntu Q&A thread and reported that he was having success with one of the tips. Since it’s been quite a while since I’ve gotten geeky here on DocumentSnap, I figure this is a good excuse.

A few notes before we get started:

  1. As I mentioned, this tip is extremely geeky and involves scripting and a command shell (aka the Terminal on macOS). If you’re not comfortable with that, you may want to give this one a pass and use something like Adobe Acrobat or macOS Preview.
  2. This tip uses a Unix tool called Ghostscript. I’ll be showing the tip on the Mac, and the page I linked to above is for Linux. There is a version of Ghostscript on Windows, but I am not sure if this tip will work with it.

Install Ghostscript

Chances are, your computer may not have Ghostscript installed (my Mac did not).

The easiest way to get Ghostscript on the Mac is to use Homebrew. If you don’t already have Homebrew, follow the instructions on the site.

Once you have Homebrew installed, install Ghostscript by going to Terminal and typing:

brew install ghostscript

Homebrew will do its magic, and you should be good to go.

Use Ghostscript to Reduce PDF File Size

In the AskUbuntu thread linked above, there are a number of suggestions. The one that Andrew recommended is this one.

I tried using screen for PDFSETTINGS, but the result looked awful. For me, ebook did the trick. There’s a tiny (to my eyes) reduction in quality, but for most of my scanned PDFs the file size was reduced quite a bit.

As a result, here’s the script that I’ve been using:

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

In this example I’m using this scanned PDF, which is 1,501,178 bytes:

I ran the script in a Terminal window to compress it:

Ghostscript Terminal Window
Ghostscript Terminal Window

You can see that it reduced the 1.5 MB file to 565 KB:

Ghostscript files
Ghostscript files

Here’s a link to the file so you can take a look. You can see it’s a liiiiittle more blurry, but not too bad.

Automating Ghostscript With Hazel

The nice thing about using a script to reduce file size is that there is the potential for automation. Here’s a quick Hazel rule I used to watch a folder and automatically reduce the file size:

Hazel Ghostscript rule
Hazel Ghostscript rule

You can see that I embedded the script above, but made some tweaks to make it work with Hazel and output to a folder called Output. You can, of course, adjust that to go to any folder.

You don’t need Ghostscript to reduce PDF files, but it’s nice to know you can

As I said earlier, you don’t need to get this geeky to make PDFs smaller. You can scan at a reduced resolution, you can use a tool like Acrobat or PDFpen, or you can use other specialized tools for your operating system. Sometimes it’s fun to bust out the Terminal though, so that’s what I did (I have a sad definition of fun, I know).

Do you use a different method? Let us know in the comments how you do it.

About the Author

Brooks Duncan helps individuals and small businesses go paperless. He's been an accountant, a software developer, a manager in a very large corporation, and has run DocumentSnap since 2008. You can find Brooks on Twitter at @documentsnap or @brooksduncan. Thanks for stopping by.

Leave a Reply 6 comments

HP Support Number - July 10, 2018 Reply

You sharing good information this is very useful for everyone.

K7 Antivirus Customer Support - June 27, 2018 Reply

Thanks for this post. Really helpful. Yes, you are right, Mac doesn’t have GhostScript in it. Thanks for sharing the installation process, and that too this accurately.

Matthew Lenz - March 8, 2018 Reply

-dCompatibilityLevel=1.4 with -dPDFSETTINGS=/ebook is redundant. It it already uses 1.4 with

    Pick - June 1, 2018 Reply

    Very interesting technology…

Ben - February 14, 2018 Reply

The link for “article-ocr-compress.pdf” seems to be broken.

William M. - February 4, 2018 Reply

Extra software is not necessarily needed on MacOS X. You can use ColorSync Utility app.

1. Open ColorSync Utility app from Applications > Utilities
2. Choose File > Open, then select your PDF document
3. When the file opens, click the Filter pop-up menu at the bottom of the window, then choose Live Update from Filter Inspector. The appearance of the PDF document will then change as you select and edit a filter in the filter inspector.
4. Create a new filter by clicking the + icon
5. Click on the dropdown to the right of your new filter Add Image Effects > Color Image Sampling and add another Add Image Effects > Image Compression
6. Play with the settings until you’re happy and proceed to Save As…. or Save the document itself and you’ll find yourself with a more compressed PDF version.

Leave a Reply: