From f85630138508b58e4849679ab63ecfec04b7bd54 Mon Sep 17 00:00:00 2001 From: Atul Anand Date: Fri, 12 Feb 2021 15:07:33 +0530 Subject: [PATCH] Did multiple changes... > Added comments for better/complete understanding (beginner could read it once and understand it). > Deleted all non-working and un-necessary code. (according to the latest version of python). --- .../Merge Multiple PDF/source-code.py | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/Applications/Merge Multiple PDF/source-code.py b/Applications/Merge Multiple PDF/source-code.py index 719ccb5..15dd917 100644 --- a/Applications/Merge Multiple PDF/source-code.py +++ b/Applications/Merge Multiple PDF/source-code.py @@ -1,14 +1,24 @@ from PyPDF2 import PdfFileMerger -import os -#var = os.getcwd() For extracting from enother folder -merger = PdfFileMerger() -for items in os.listdir(): - if items.endswith('.pdf'): - merger.append(items) -merger.write("Final_pdf.pdf") +# Download the following library using pip. +import os +# The above library already in your library. + +# Make a function of PyPDF2 a variable. merger = PdfFileMerger() -with open(originalFile, 'rb') as fin: - merger.append(PdfFileReader(fin)) -os.remove(originalFile) + +# Run the for loop to scan through all the pdf files. +# If wanted you can also just put the names of files instead of scanning all the files. +for items in os.listdir(): # os.listdir mean that it will scan through all the files. + # This is an endswith function to check the extension of the object. + if items.endswith('.pdf'): + # This will append/add all projects. + merger.append(items) + +# This will write the whole document/ add it together into a new pdf. +merger.write("Rename.pdf") # The name can easily be changed. + merger.close() +# This project is edited by Atul Anand based upon python version 3.9. +# I can assure you that this project will properly work if you use the latest version of python. +# Check my version of this project and many other projects on github.com/AtulACleaver.