I have a large number of PDF files which have two slides to a page (for printing).
The format is A4 pages each with two slides setup like so:
-----------
Here is how I did it with pdfrw
:
import sys, os, pdfrw
writer = pdfrw.PdfWriter()
for page in pdfrw.PdfReader('input.pdf').pages:
for y in [0, 0.5]:
newpage = pdfrw.PageMerge()
newpage.add(page, viewrect=(0, y, 1, 0.5))
writer.addpages([newpage.render()])
writer.write('output.pdf')
Short and working!
If you want it rotated (example: input A4 portrait, output 2 A5 portrait and not landscape):
import sys, os, pdfrw
writer = pdfrw.PdfWriter()
for page in pdfrw.PdfReader('input.pdf').pages:
for y in [0, 0.5]:
newpage = pdfrw.PageMerge()
newpage.add(page, viewrect=(0, y, 1, 0.5))
p = newpage.render()
p.Rotate = 270
writer.addpages([p])
writer.write('output.pdf')