Use a free third-party Java tool to truly compress PDFs
Jan 15, '10 07:30:00AM
Contributed by: Sveto
All methods I have tried so far to compress PDFs have never really lived up to what I needed. Unless you are ready to pay for a commercial product, you are basically left to deal with the ColorSync options, which are extremely damaging to a PDF created by the Mac OS, or to the other extreme, simply do not compress and actually make the resulting file bigger. You also can't remove the fonts from a PDF with ColorSync.
So I put together a few tidbits of advice I found on the net, and came up with a robust solution that's both free and works from the Print dialog box. Here the details.
First of you need to get Multivalent, which is a free product (at least for our purposes, it is free). As of this writing, however, the latest version is missing the Tools component (it's undergoing a heavy revision), and that would break our setup. So you need to get this older version: Multivalent20060102.jar. You can find it at any of these sites:
site 1 | site 2 | site 3
(links courtesy of math_crank).
Once you have this downloaded, rename it to Multivalent.jar for simplicity, and place it in the following location:
/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/ext
[robg adds: Read my footnote at the end for a method of using this tool without installing it in the /System folder.]
If you have an older version of java, you will have to adjust the above address; mine is 1.6.0. Now open Automator and create a workflow. Drag the Run Shell Script action to the work area. In that action, change the pop-up for the code to as arguments, and paste the following:
cat "$1" > /Users/your_name/Desktop/PDF/temp$$.pdf && java tool.pdf.Compress -compatible -noembed -noalt -jpeg /Users/your_name/Desktop/PDF/temp$$.pdf && rm /Users/your_name/Desktop/PDF/temp$$.pdf
Change your_name to whatever your home directory is called, and if that name has spaces in it, you'll need to either escape them with a backslash, or enclose the entire directory name in quotes.
Save your workflow as Truly Compress PDF.workflow in the PDF Services folder in either in your home Library, or in the top-level Library.
On the Desktop, create a folder (named PDF in the sample workflow) that will be receiving your compressed files. You will have to change the name of the file to your desired name, as the above workflow creates a generic tempXXX-o.pdf name. For anything you need to print as a PDF, go to Print » PDF » Truly Compress PDF (or whatever you named it).
This works well under Snow Leopard, but I'd guess with small changes to the save location for Multivalent, it would function on previous OS versions.
You can add or remove arguments in the script line according to what you desire. Read about the options on the PDF Compress on the Mutivalent site. But I have used a nice once, and as long as you don't need fancy fonts, it will squeeze your files almost without any quality losses.
I don't have more time to spend on this, but it would be great if someone could expand the script and/or make changes to the Automator workflow, so when we select that workflow we get a "Save As" window and than name the file at once the proper way. If that's done, the need for a PDF folder will vanish, and the temp file can be created and deleted in the temp directory and not on the Desktop. Any help in this respect will be gladly appreciated.
[robg adds: You can also find the older version of Multivalent at SourceForge. I wanted to test this hint, but didn't want to install anything in my /System folder, and my Mac Pro still runs 10.5, so here's how I modified it. First I put Multivalent in its own folder named pdftools in my user's bin folder (which I've previously created).
In Terminal, I then ran these commands to expand and then remove the jar file:
$ cd ~/bin
$ jar xfv Multivalent20060102.jar
$ rm Multivalent20060102.jar
Once expanded like this, you can directly access the various tools by running them from that directory. So I modified the workflow to read as follows:
cat "$1" > /Users/your_name/Desktop/PDF/temp$$.pdf && java /Users/your_name/bin/pdftools/tool.pdf.Compress -compatible -noembed -noalt -jpeg /Users/your_name/Desktop/PDF/temp$$.pdf && rm /Users/your_name/Desktop/PDF/temp$$.pdf
As above, replaced your_name with your user's name, and modify the path to the expanded Multivalent bundle as appropriate. Used in this manner, it worked perfectly (in 10.5, and I assume, in 10.6) without modifying the /System folder.]
Comments (12)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20100111142051154