pyPdf库 ( http://pybrary.net/pyPdf/ ) ,操作起来相当直接易懂,把代码贴在这儿,做个记录。
1 from pyPdf import PdfFileWriter, PdfFileReader
2
3 pdf = PdfFileReader(file(‘original.pdf‘, ‘rb‘))
4 out = PdfFileWriter()
5
6 for page in pdf.pages:
7 page.mediaBox.upperRight = (580,800)
8 page.mediaBox.lowerLeft = (128,232)
9 out.addPage(page)
10
11 ous = file(‘target.pdf‘, ‘wb‘)
12 out.write(ous)
13 ous.close()
2
3 pdf = PdfFileReader(file(‘original.pdf‘, ‘rb‘))
4 out = PdfFileWriter()
5
6 for page in pdf.pages:
7 page.mediaBox.upperRight = (580,800)
8 page.mediaBox.lowerLeft = (128,232)
9 out.addPage(page)
10
11 ous = file(‘target.pdf‘, ‘wb‘)
12 out.write(ous)
13 ous.close()
Enjoy!