File: add_bleed.py

package info (click to toggle)
python-reportlab 3.1.8-3%2Bdeb8u1
  • links: PTS
  • area: main
  • in suites: jessie
  • size: 6,996 kB
  • ctags: 9,483
  • sloc: python: 69,727; ansic: 19,108; xml: 1,494; makefile: 416; java: 193; sh: 100
file content (28 lines) | stat: -rw-r--r-- 966 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#How to add bleed to a page in this case 6mm to a landscape A4
from reportlab.lib import units, pagesizes
from reportlab.pdfgen.canvas import Canvas
import sys, os, glob, time
bleedX = 6*units.mm
bleedY = 6*units.mm
pageWidth, pageHeight = pagesizes.landscape(pagesizes.A4)
def process_pdf(c,infn,prefix='PageForms'):
    from rlextra.pageCatcher import pageCatcher
    names, data = pageCatcher.storeFormsInMemory(open(infn,'rb').read(),prefix=prefix,all=1)
    names = pageCatcher.restoreFormsInMemory(data,c)
    del data
    for i in range(len(names)):
        thisname = names[i]
        c.saveState()
        c.translate(bleedX,bleedY)
        c.doForm(thisname)
        c.restoreState()
        c.showPage()

def main():
    for infn in sys.argv[1:]:
        outfn = 'bleeding_'+os.path.basename(infn)
        c = Canvas(outfn,pagesize=(pageWidth+2*bleedX,pageHeight+2*bleedY))
        process_pdf(c,infn)
        c.save()
if __name__=='__main__':
    main()