Created
January 11, 2021 07:06
-
-
Save haider11234/e174c4e8b824cf6151e0fd4f1a1efc96 to your computer and use it in GitHub Desktop.
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
from PyPDF2 import PdfFileReader, PdfFileWriter | |
def merge_pdfs(filenames): | |
pdf_writer = PdfFileWriter() | |
for path in filenames: | |
pdf_reader = PdfFileReader(path) | |
for page in range(pdf_reader.getNumPages()): | |
# Add each page to the writer object | |
pdf_writer.addPage(pdf_reader.getPage(page)) | |
# Write out the merged PDF | |
with open("merge.pdf", 'wb') as out: | |
pdf_writer.write(out) | |
filenames = ['doc1.pdf', 'doct2.pdf'] | |
merge_pdfs(filenames) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment