Skip to content

Instantly share code, notes, and snippets.

@jrk jrk/README.md
Last active Jan 27, 2016

Embed
What would you like to do?
Executable script to run Quartz filters on a PDF file from the shell

This is a simple, should-be-drop-in replacement for the old /System/Library/Printers/Libraries/quartzfilter utility which went away circa OS X 10.8.

Usage:

chmod +x quartzfilter.js
./quartzfilter.js infile.pdf filter.qsfilter outfile.pdf

e.g.,

./quartzfilter.js my-big-pdf.pdf "/System/Library/Filters/Reduce File Size.qfilter" my-less-big-pdf.pdf

Built using direct calls into Quartz.framework from JavaScript for Automation (JSX).

#!/usr/bin/env osascript -l JavaScript
ObjC.import("Foundation")
ObjC.import("Quartz")
ObjC.import("stdlib")
function save(inpath, filterpath, outpath) {
inURL = $.NSURL.fileURLWithPath(inpath)
inPDF = $.PDFDocument.alloc.initWithURL(inURL)
filterURL = $.NSURL.fileURLWithPath(filterpath)
filter = $.QuartzFilter.quartzFilterWithURL(filterURL)
inPDF.writeToFileWithOptions(outpath, $({"QuartzFilter": filter}))
}
function run(argv) {
if (argv.length != 3) {
console.log("Usage: quartzfilter.js inPDF qsfilter outPDF")
$.exit(-1)
}
save(argv[0], argv[1], argv[2])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.