Reputation: 93
I'm trying to convert a series of pdf files to 2up so they can be read like a magazine.
I've seen the pdfjam scripts, which seem quite complex to install on Mac, so I tried using PyPDF2
. I thought I could use the setPageLayout('/TwoPageRight')
method on a PdfFileMerger
object, then merge the input file.
But this doesn't change the output format at all.
Any idea what I'm doing wrong? Is there a better way?
Upvotes: 2
Views: 736
Reputation: 93
As mentioned in my comment, I found a solution at https://github.com/py-pdf/cpdf/blob/main/cpdf/up2.py
reader = PdfReader("example.pdf")
writer = PdfWriter()
for i in range(0, len(reader.pages) - 1, 2):
lhs = reader.pages[i]
rhs = reader.pages[i + 1]
lhs.mergeTranslatedPage(rhs, float(lhs.mediabox.right), 0, True)
writer.add_page(lhs)
with open("2-up.pdf", "wb") as fp:
writer.write(fp)
Upvotes: 1