Created
April 5, 2020 20:01
-
-
Save vinovator/62aa9cd6577a189543e7ce651e2229d7 to your computer and use it in GitHub Desktop.
From a given folder, consolidate all PDFs into one
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
# -*- coding: utf-8 -*- | |
""" | |
Python 3 | |
ConsolidatePDF.py | |
From a given folder, consolidate all PDFs into one | |
""" | |
from PyPDF2 import PdfFileMerger | |
import os | |
if __name__=="__main__": | |
pdf_path = "..\PDF_PATH" | |
target_pdf_name = "Target.pdf" | |
pdf_merger = PdfFileMerger() | |
for path, dirs, files in os.walk(pdf_path): | |
for f in files: | |
f_name, extn = os.path.splitext(f) | |
if (extn == ".pdf"): | |
print("Consolidating {}".format(f)) | |
pdf_merger.append(os.path.join(pdf_path + "\\" + f)) | |
# Open target file in binady mode | |
with open(os.path.join(pdf_path + "\\" + target_pdf_name), "wb") as fh: | |
pdf_merger.write(fh) | |
print("done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment