Last active
October 22, 2019 06:48
-
-
Save roycechua/e5c662b1d0837f6dedea569cab40318c to your computer and use it in GitHub Desktop.
PyPDF2 code to append/Stitch two PDF files into one single file. This is just a proof of the idea but the more optimal thing to do would be to determine the total number of pages per file.
This file contains hidden or 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
| from PyPDF2 import PdfFileReader, PdfFileWriter | |
| from PyPDF2.pdf import PageObject | |
| writer = PdfFileWriter() | |
| reader = PdfFileReader(open("1.2.1.13 Lab - Research Computer Components.pdf",'rb')) | |
| for i in range(3): | |
| page = reader.getPage(i) | |
| writer.addPage(page) | |
| sup_reader = PdfFileReader(open("Week1_Introduction to Machine Learning and Toolkit.pdf",'rb')) | |
| for i in range(3): | |
| page = sup_reader.getPage(i) | |
| writer.addPage(page) | |
| with open('out.pdf', 'wb') as f: | |
| writer.write(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment