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

Coding Is Fun
Coding Is Fun
8.9 هزار بار بازدید - 3 سال پیش - 👉 Explore All My Excel
👉 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-...
_________________________
👩‍💻 [OPTIONAL] VBA snippet to select a folder:
https://gist.github.com/Sven-Bo/53663...
_________________________
📝 𝗦𝗢𝗨𝗥𝗖𝗘 𝗖𝗢𝗗𝗘:
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()


𝗧𝗢𝗢𝗟𝗦 𝗔𝗡𝗗 𝗥𝗘𝗦𝗢𝗨𝗥𝗖𝗘𝗦
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
🆓【𝗙𝗥𝗘𝗘】Excel Add-in (𝗠𝘆𝗧𝗼𝗼𝗹𝗕𝗲𝗹𝘁): https://pythonandvba.com/mytoolbelt
📊 Data Visualization Excel Add-In (𝗚𝗿𝗮𝗳𝗹𝘆): https://pythonandvba.com/grafly
🤪 Fun Emoji Excel Add-In (𝗘𝗺𝗼𝗷𝗶𝗳𝘆): https://pythonandvba.com/emojify
📑 Excel Templates: https://pythonandvba.com/go/excel-tem...
🎓 My Courses: https://pythonandvba.com/go/courses
📚 Books, Tools, and More: https://pythonandvba.com/resources


𝗖𝗢𝗡𝗡𝗘𝗖𝗧 𝗪𝗜𝗧𝗛 𝗠𝗘
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
🔗 LinkedIn: LinkedIn: sven-bosau
📸 Instagram: Instagram: codingisfun_official
💻 GitHub: https://github.com/Sven-Bo
💬 Discord: https://pythonandvba.com/discord
📬 Contact: https://pythonandvba.com/contact


☕ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲?
If you want to support this channel, you can buy me a coffee here: https://pythonandvba.com/coffee-donation
3 سال پیش در تاریخ 1400/01/27 منتشر شده است.
8,941 بـار بازدید شده
... بیشتر