Exemple #1
0
if __name__ == '__main__':

    # OPTIONS: Set the distance from bottom left of page;
    # Set the angle and opacity of text
    # Font must be the PostScript name (i.e. no spaces) (See Get Info in FontBook)
    xOffset, yOffset, angle, opacity = 110.0, 200.0, 45.0, 0.5
    font = selectFont('Helvetica-Bold', 150.0)
    text = "SAMPLE"

    for filename in sys.argv[1:]:
        shortName = os.path.splitext(filename)[0]
        outFilename = getFilename(shortName, " WM")
        pdf = createPDFDocumentFromPath(filename)
        metaDict = getDocInfo(filename)
        writeContext = createOutputContextWithPath(outFilename, metaDict)
        pages = Quartz.CGPDFDocumentGetNumberOfPages(pdf)

        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)
                    astr = CFAttributedStringCreate(
                        kCFAllocatorDefault, text,
                        {kCTFontAttributeName: font})
                    line = CTLineCreateWithAttributedString(astr)
                    drawWatermarkText(writeContext, line, xOffset, yOffset,
Exemple #2
0
        CG.CGContextTranslateCTM(ctx, imageWidth / 2, imageHeight / 2)
        CG.CGContextRotateCTM(ctx, angle * math.pi / 180)
        CG.CGContextTranslateCTM(ctx, -imageWidth / 2, -imageHeight / 2)
        CG.CGContextSetTextPosition(ctx, 0.0, 0.0)
        CTLineDraw(line, ctx)
        CG.CGContextRestoreGState(ctx)


if __name__ == '__main__':

    for filename in sys.argv[1:]:
        shortName = os.path.splitext(filename)[0]
        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)