-
-
Save stanislaw/2c9a3e492adf0e62e75b6fef4bd7a8a7 to your computer and use it in GitHub Desktop.
Splits a PDF file for manual double-side printing
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 python3 | |
import sys, os | |
from PyPDF2 import PdfFileReader, PdfFileWriter | |
inputname = sys.argv[1] | |
pdf = PdfFileReader(inputname) | |
numpages = pdf.getNumPages() | |
if numpages % 2 == 1: | |
numpages = numpages - 1 | |
pdf_writer = PdfFileWriter() | |
pdf_writer.addPage(pdf.getPage(numpages)) | |
with open("last.pdf", "wb") as out: | |
pdf_writer.write(out) | |
odd = PdfFileWriter() | |
even = PdfFileWriter() | |
for i in range(numpages): | |
page = pdf.getPage(i) | |
if (i % 2) == 1: | |
odd.addPage(page) | |
else: | |
even.addPage(page) | |
with open("odd.pdf", "wb") as out: | |
odd.write(out) | |
with open("even.pdf", "wb") as out: | |
even.write(out) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment