Update: Thanks to stardt whose script is working! PDF is another page. I tried the script on a different one and it also correctly bound each pdf page, but the page number order is sometimes correct and sometimes incorrect. For example, on page 25-28 pdf of the file the number of printed pages is 14, 15, 17, 16. I was wondering why? The entire pdf file can be downloaded from http://download304.mediafire.com/u6ewhjt77lzg/bgf8uzvxatckycn/3.pdf
Original: I have a scanned pdf file where two paper pages sit side by side on the pdf page. I would like to split the pdf page into two parts, with the original left half becoming the first of two new PDF pages. PDF looks like
.
Here is my Python script called un2up inspired by Gilles :
#!/usr/bin/env python import copy, sys from pyPdf import PdfFileWriter, PdfFileReader input = PdfFileReader(sys.stdin) output = PdfFileWriter() for p in [input.getPage(i) for i in range(0,input.getNumPages())]: q = copy.copy(p) (w, h) = p.mediaBox.upperRight p.mediaBox.upperLeft = (0, h/2) p.mediaBox.upperRight = (w, h/2) p.mediaBox.lowerRight = (w, 0) p.mediaBox.lowerLeft = (0, 0) q.mediaBox.upperLeft = (0, h) q.mediaBox.upperRight = (w, h) q.mediaBox.lowerRight = (w, h/2) q.mediaBox.lowerLeft = (0, h/2) output.addPage(q) output.addPage(p) output.write(sys.stdout)
I tried the script in the pdf connector with the command un2up < page.pdf > out.pdf , but the output of out.pdf not correctly divided.
I also checked the values ββof the variables w and h , the output of p.mediaBox.upperRight , and they are 514 and 1224 , which do not look right depending on their actual relationship.
The file can be downloaded from http://download851.mediafire.com/bdr4sv7v5nzg/raci13ct5w4c86j/page.pdf .
python pdf pypdf
Tim
source share