Last active
August 29, 2015 14:21
-
-
Save dinigo/ae358bd01ae5f87e3c2f to your computer and use it in GitHub Desktop.
Split pdf pages wich contains slides so that every page contains just one slide. It only works with two slides per page, either horizontal or vertical.
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
#!/usr/bin/env python | |
# Based on http://unix.stackexchange.com/a/12483 | |
# To use it you have to give it execution privilleges | |
# with the command: | |
# chmod u+x split.py | |
# Then you can use it like this: | |
# ./split.py <slides.pdf >split.pdf | |
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())]: | |
u = copy.copy(p) | |
d = copy.copy(p) | |
(xur, yur) = p.mediaBox.upperRight | |
(xll, yll) = p.mediaBox.lowerLeft | |
if xll > yll: | |
# horizontal | |
u.mediaBox.upperRight = (xur/2, yur) | |
d.mediaBox.lowerLeft = (xur/2, yll) | |
else: | |
# vertical | |
u.mediaBox.lowerLeft = (xll, yur/2) | |
d.mediaBox.upperRight = (xur, yur/2) | |
output.addPage(u) | |
output.addPage(d) | |
output.write(sys.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment