Skip to content

Instantly share code, notes, and snippets.

@mickn
Created October 30, 2016 08:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mickn/9d87decf58e51382d95e501f75142571 to your computer and use it in GitHub Desktop.
Save mickn/9d87decf58e51382d95e501f75142571 to your computer and use it in GitHub Desktop.
Split PDF with spreads into separate pages
#!/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.upperRight = (w/2, h)
q.mediaBox.upperLeft = (w/2, h)
output.addPage(p)
output.addPage(q)
output.write(sys.stdout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment