Back to Browse

How to Merge Multiple PDF Files in Excel Using Python (fast & easy)

10.2K views
Apr 17, 2021
7:34

๐Ÿ‘‰ Explore All My Excel Solutions: https://pythonandvba.com/solutions ๐——๐—˜๐—ฆ๐—–๐—ฅ๐—œ๐—ฃ๐—ง๐—œ๐—ข๐—ก โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ Did you know you can use Python code to merge PDF files in Excel? In this video, I am going to show you how to merge multiple PDF files in Excel using Python. It is a real time saver and will allow you to quickly combine the files. For this particular tutorial, we will be using the Python libraries xlwings & PyPDF2 to combine the PDF Files in Microsoft Excel. You can find the Excel PDF Merger App here: ๐Ÿ‘‰ https://github.com/Sven-Bo/merge-pdf-files-in-excel _________________________ ๐Ÿ‘ฉโ€๐Ÿ’ป [OPTIONAL] VBA snippet to select a folder: https://gist.github.com/Sven-Bo/536638ebae21d6effe184edeb12d0a50 _________________________ ๐Ÿ“ ๐—ฆ๐—ข๐—จ๐—ฅ๐—–๐—˜ ๐—–๐—ข๐——๐—˜: from pathlib import Path # Standard Python Library import xlwings as xw # pip install xlwings from PyPDF2 import PdfFileMerger, PdfFileReader # pip install PyPDF2 # ---Documentations: # PyPDF2: https://pythonhosted.org/PyPDF2/ # xlwings: https://docs.xlwings.org/en/stable/ def main(): wb = xw.Book.caller() sheet = wb.sheets[0] merger = PdfFileMerger() sheet.range("status").clear_contents() source_dir = sheet.range("source_dir").value output_name = sheet.range("output_name").value + ".pdf" pdf_files = list(Path(source_dir).glob("*.pdf")) for pdf_file in pdf_files: merger.append(PdfFileReader(str(pdf_file), "rb")) output_path = str(Path(__file__).parent / output_name) merger.write(output_path) sheet.range("status").value = f"The file have been saved here: {output_path}" if __name__ == "__main__": xw.Book("pdfmerger.xlsm").set_mock_caller() main() ๐—–๐—ข๐—ก๐—ก๐—˜๐—–๐—ง ๐—ช๐—œ๐—ง๐—› ๐— ๐—˜ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ ๐Ÿ”— LinkedIn: https://www.linkedin.com/in/sven-bosau/ ๐Ÿ“ฌ Contact: https://pythonandvba.com/contact โ˜• ๐—•๐˜‚๐˜† ๐—บ๐—ฒ ๐—ฎ ๐—ฐ๐—ผ๐—ณ๐—ณ๐—ฒ๐—ฒ? If you want to support this channel, you can buy me a coffee here: โ–ถ https://pythonandvba.com/coffee-donation

Download

1 formats

Video Formats

360pmp412.8 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

How to Merge Multiple PDF Files in Excel Using Python (fast & easy) | NatokHD