from glob import glob from StringIO import StringIO from pyPdf import

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
from glob import glob
from StringIO import StringIO
from pyPdf import PdfFileWriter, PdfFileReader
for name in glob('*.pdf'):
output = PdfFileWriter()
input = PdfFileReader(open(name, 'rb'))
for x in xrange(input.numPages):
page = input.getPage(x)
box = page.mediaBox
box.upperLeft = (box.getUpperLeft_x() / 1.1, box.getUpperLeft_y() / 1.1)
box.lowerLeft = (box.getLowerLeft_x() + 50, box.getLowerLeft_y() + 50)
output.addPage(page)
buf = StringIO()
output.write(buf)
open(name, 'w').write(buf.getvalue())