-   Linux - Newbie (
-   -   TIP: Reducing PDF file size from the command line with GhostScript (gs) (

ShellyCat 01-15-2011 12:41 AM

TIP: Reducing PDF file size from the command line with GhostScript (gs)
I've spent hours trying to scan + shrink a multipage PDF document without losing readability. This is the first time I've ever needed to do this! (I had to scan each page as ".jpg" in order to email and open on another computer, so I could not scan to PDF directly, which I think is why each page was so large; lower DPIs made the text too blurry.)

I found this great tip on UbuntuGeek...but anyone can do this if GhostScript is installed:

Many thanks to whoever posted this tip!

business_kid 01-15-2011 03:49 AM

I tried it on a 139k text pdf and I got a 149k one! :-o.

tolstoyleo 07-11-2012 03:37 PM

I know this is an old thread but this thread is at the top of a google search when looking to reduce file size, the command is:


gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
Some things that currently happen while running this command with the current apt-get install ghostscript version:

1: you need to specify a different output file name than the input file name, which is annoying, or else the outputted pdf will be blank / white.

2: if the pdf is not flattened (e.g. there's masked images), you'll get weird output, like missing backgrounds or missing images, what I ended up doing to fix this is using imagemagick's convert to jpg since jpg format doesn't have alpha channel (flat):


convert input.pdf input.jpg

convert input.jpg input.pdf
And then ran the ghostscript snippet above to reduce filesize, and so far that's been working for me well.

Hope this helps someone.

business_kid 07-12-2012 05:11 AM

Welcome to LQ

Thank you for the update for posterity. Please mention your ghostscript version. Post the output of

gs -h | head -n 1
as there's a couple of different ghostscripts.

All times are GMT -5. The time now is 06:48 AM.