Max OS-X: Shrink PDF files in the Finder
- Published: Sunday, 05 May 2013 00:00
Today I finally got around to use Automator, and make one of the command line scripts I have been running for ages a little easier to use.
The problem I have been trying to solve is the fact that the PDF files that a Mac creates are normally of very high quality and hence large. If you just want to send someone a document for reading on screen, a much smaller PDF file would do. The open source package “ghostscript” has a tool called ps2pdf that can be (ab)used to adjust the size of components for PDF files. I installed this in /opt/local/bin using the “macports” software.
To make it possible to do the PDF-shrinking from the Finder, I started automator, and made a new “Service”. I instructed it to use PDF files, and only in the Finder. In the workflow, I added a “run shell script” step. The system passes the files as arguments to this script.
The contents of the script are:
export PATH=$PATH:/opt/local/bin for f in "$@" do echo "$f" d=`dirname "$f"` cd "$d" b=`basename "$f"` ps2pdf -dPDFSETTINGS=/ebook "$b" # Choose /screen for even smaller PDF, or # /printer /prepress or /default for successively larger if [ -f "$b".pdf ]; then mv "$b" "$b".old mv "$b".pdf "$b" else echo "Apparently conversion failed" fi done
I saved this as the service named “Small PDF”, and Done!
And using it is even easier: