Created
March 3, 2017 17:22
-
-
Save mike-anderson/cfb47e26bf6be1f063d38fd33df28d13 to your computer and use it in GitHub Desktop.
mix two pdfs with odd and even pages from a document feeder scanner
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/local/bin/python | |
from PyPDF2 import PdfFileReader, PdfFileWriter | |
import sys | |
if len(sys.argv) < 4: | |
print "usage: mix.py odd.pdf even.pdf result.pdf" | |
exit() | |
odd = PdfFileReader(open(sys.argv[1],'rb')).pages | |
even = PdfFileReader(open(sys.argv[2],'rb')).pages | |
if (len(odd) - len(even) > 1) or (len(odd) < len(even)): | |
print "document length must match or even document must be one page less" | |
exit() | |
writer = PdfFileWriter() | |
for n in range(0,len(odd)): | |
writer.addPage(odd[n]) | |
if n < len(even): | |
writer.addPage(even[-(n+1)]) | |
writer.write(open(sys.argv[3], 'wb')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you will need a pip install pypdf2