February 18, 2004
(This post is from my old, old, super old site. My views have changed over the years, hopefully my writing has improved, and there is now more than a handful of folks reading my site. Enjoy.)
Wednesday, February 18th, 2004
#!/usr/bin/python
#usage: pdfmerge.py outfile a.pdf b.pdf ...
from CoreGraphics import * import sys, os, math, getopt, string
outfile = sys.argv[1] page_rect = CGRectMake (0, 0, 612, 792)
c = CGPDFContextCreateWithFilename (outfile, page_rect)
for file in sys.argv[2:]: pdf = CGPDFDocumentCreateWithProvider( CGDataProviderCreateWithFilename(file) ) for p in range (1, pdf.getNumberOfPages () + 1): r = pdf.getMediaBox (p) c.beginPage(r) c.drawPDFDocument(r, pdf, p) c.endPage() c.finish ()
And of course, I don't actually bother with error checking and such. That's um.. left as an exercise to the reader because I'm lazy.
-- posted 3:54 pm