Skip to content

Instantly share code, notes, and snippets.

@mike-anderson
Created March 3, 2017 17:22
Show Gist options
  • Save mike-anderson/cfb47e26bf6be1f063d38fd33df28d13 to your computer and use it in GitHub Desktop.
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
#!/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'))
@mike-anderson
Copy link
Author

you will need a pip install pypdf2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment