Last active
November 13, 2023 10:10
-
-
Save CookieLau/1494d11c657c4637e1d5a3fccabe29af to your computer and use it in GitHub Desktop.
A CLI PDF Merger tool
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 PdfMerger | |
import os | |
from tqdm import tqdm | |
directory = input("Please input the directory containing all pdfs: ") | |
#Create an instance of PdfFileMerger() class | |
merger = PdfMerger() | |
#Create a list with the file paths | |
pdf_files = sorted(filter(lambda x:x.lower().endswith(".pdf"), os.listdir(directory))) | |
print("The pdfs to be merged: ") | |
print(pdf_files) | |
merge = input("Start merging... [Y/N]") | |
if merge != "Y": | |
exit() | |
os.chdir(directory) | |
#Iterate over the list of the file paths | |
for pdf_file in tqdm(df_files): | |
#Append PDF files | |
merger.append(pdf_file) | |
#Write out the merged PDF file | |
merger.write("merged_pdfs.pdf") | |
merger.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment