Created
September 23, 2011 12:43
-
-
Save akandratovich/1237245 to your computer and use it in GitHub Desktop.
Script for cropping pdf books
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyPdf import PdfFileWriter as pw, PdfFileReader as pr | |
# crop in_file | |
in_file = 'file.pdf' | |
out_file = 'file.crop.pdf' | |
out_pdf = pw() | |
in_pdf = pr(file(in_file, 'rb')) | |
for p in range(in_pdf.getNumPages()): | |
page = in_pdf.getPage(p) | |
# [0, 0, 612, 792] | |
mb = page.mediaBox | |
mb.setUpperRight((420, 540)) | |
mb.setLowerLeft((80, 20)) | |
out_pdf.addPage(page) | |
out_pdf.write(file(out_file, 'wb')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment