writeContext = createOutputContextWithPath(outFilename, metaDict) pages = Quartz.CGPDFDocumentGetNumberOfPages(pdf) # OPTIONS: Set the RELATIVE distance from outside top corner of page; # For other uses, set the angle, scale, and opacity of text # Font must be the PostScript name (i.e. no spaces) (See Get Info in FontBook) xOffset, yOffset, angle, scale, opacity = 45.0, 45.0, 0.0, 1.0, 1.0 font = selectFont('TimesNewRomanPSMT', 12.0) if pdf: for i in range(1, (pages + 1)): page = Quartz.CGPDFDocumentGetPage(pdf, i) if page: mbox = Quartz.CGPDFPageGetBoxRect(page, Quartz.kCGPDFMediaBox) if Quartz.CGRectIsEmpty(mbox): mbox = None Quartz.CGContextBeginPage(writeContext, mbox) Quartz.CGContextDrawPDFPage(writeContext, page) text = str(i) astr = CFAttributedStringCreate( kCFAllocatorDefault, text, {kCTFontAttributeName: font}) line = CTLineCreateWithAttributedString(astr) x = Quartz.CGRectGetWidth(mbox) y = Quartz.CGRectGetHeight(mbox) y -= yOffset if i == 1: # Don't put number on page 1 pass elif i % 2 == 1: # Move right hand number in by its own width. textWidth = astr.size().width x = x - xOffset
outFilename = shortName + " NUM.pdf" pdf = createPDFDocumentFromPath(filename) ctx = createOutputContextWithPath(outFilename) pages = CG.CGPDFDocumentGetNumberOfPages(pdf) # OPTIONS: Set the RELATIVE distance from outside top corner of page; # For other uses, set the angle, scale, and opacity of text # Font must be the PostScript name (i.e. no spaces) (See Get Info in FontBook) xOffset, yOffset, angle, scale, opacity = 45.0, 45.0, 0.0, 1.0, 1.0 font = CTFontCreateWithName('TimesNewRomanPSMT', 12.0, None) if pdf: for i in range(1, (pages + 1)): page = CG.CGPDFDocumentGetPage(pdf, i) if page: mbox = CG.CGPDFPageGetBoxRect(page, CG.kCGPDFMediaBox) if CG.CGRectIsEmpty(mbox): mbox = None CG.CGContextBeginPage(ctx, mbox) CG.CGContextDrawPDFPage(ctx, page) text = str(i) print i astr = CFAttributedStringCreate( kCFAllocatorDefault, text, {kCTFontAttributeName: font}) line = CTLineCreateWithAttributedString(astr) x = CG.CGRectGetWidth(mbox) y = CG.CGRectGetHeight(mbox) y -= yOffset if i == 1: # Don't put number on page 1 pass elif i % 2 == 1: x = xOffset