Skip to content

Instantly share code, notes, and snippets.

Last active May 15, 2019 13:08
What would you like to do?
from PyPDF2 import PdfFileReader, PdfFileWriter
from PyPDF2.pdf import PageObject
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('first', help='First file (first page becomes first page)')
parser.add_argument('second', help='Second file (first page becomes second page)')
parser.add_argument('output', nargs='?', help='Output file name (optional)')
args = parser.parse_args()
if args.output:
output_file = args.output
output_file = args.first[:-4] + '_merged.pdf'
reader = PdfFileReader(open(args.first,'rb'))
sup_reader = PdfFileReader(open(args.second,'rb'))
writer = PdfFileWriter()
for pageNo in range(reader.getNumPages() + sup_reader.getNumPages()):
if (pageNo < reader.getNumPages()):
if (pageNo < sup_reader.getNumPages()):
with open(output_file, 'wb') as f:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment