A question came up on the mac-python mailing list, on how to merge some pdf's together. For future reference (for myself and others), here is one way to do it:
#!/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.comments (2) # posted 3:54 pm (uct-6)