Shrinkpdf: shrink PDF files with Ghostscript

The simplest shell script in the world to shrink your PDFs (as in reduce filesize) under Linux with Ghostscript. Inspired by some code I found in an OpenOffice Python script (I think). It feeds an existing PDF through Ghostscript, downsamples the images to 72dpi, and does some other stuff. Pretty straightforward.

shrinkpdf.sh

#!/bin/bash

gs	-q -dNOPAUSE -dBATCH -dSAFER \
	-sDEVICE=pdfwrite \
	-dCompatibilityLevel=1.3 \
	-dPDFSETTINGS=/screen \
	-dEmbedAllFonts=true \
	-dSubsetFonts=true \
	-dColorImageDownsampleType=/Bicubic \
	-dColorImageResolution=72 \
	-dGrayImageDownsampleType=/Bicubic \
	-dGrayImageResolution=72 \
	-dMonoImageDownsampleType=/Bicubic \
	-dMonoImageResolution=72 \
	-sOutputFile=out.pdf \
	 $1

Usage

Get the script by clicking the filename at the top of the box. Then run:

./shrinkpdf.sh yourfile.pdf

This produces a shrunken file named out.pdf in the current directory.

Sorry, windows users; this one is Linux only. Ghostscript does run under Windows, but I don't know much about Windows scripting. You could try typing all these parameters on the commandline by hand.

Last modified: 2008-04-21 at 16:56:16
Contact