Wednesday, October 29, 2008
Downsampling
We're going to make PDFs available for some titles - obviously we don't want to release the full-sized production PDFs as their size (often in the hundreds of megabytes) makes them unwieldy.
RubberStamp will now kick out a recompressed PDF as part of the import process. This uses the astoundingly handy Quartz Filter system of OS X. We've created a filter which downsamples all images to "screen resolution" and applies fairly hefty jpg compression, bringing the typical file size down to a few MB.
You can apply filters directly in OS X 10.5 as part of the PDFDocument writeToFile options; a couple of our import machines are still running 10.4 so we have to fire up an external task to invoke the filter. This is the quartzfilter utility in /System/Library/Printers/Libraries .
Further complications: quartzfilter seems to be picky on 10.4 about where it will pick up filters. I tried embedding the filter into RubberStamp as an application resource, and this works fine on 10.5 but is ignored by quartzfilter on 10.4. Putting the filter in ~/Library/Filters works fine on both, so that's what we're doing.
Filtering the pdf also seems to strip out the pages' CropBox and TrimBox settings - RubberStamp's now collecting the TrimBox settings for each page, applying the filter and then resetting the CropBoxes to match the original TrimBoxes. Most PDF readers will use the CropBox to clip the page, so we want to set it to match the intended display area.
Finally we strip out our production-specific annotations to give a clean, small PDF ready for the public.
Now to deliver it...
T