Convert all individual Microsoft Word Documents (.docx) files in a folder to pdf format using Python

Опубликовано: 11 Октябрь 2024
на канале: Too Long; Didn't Watch Tutorials
2,141
27

This video shows you how to convert all .docx files in a folder to .pdf without having to individually open each docx file and save as a pdf file. Unfortunately, there is no native way to do this in Microsoft Word or Adobe Acrobat, but thankfully this video will show you how in Python!

Full code below:

from docx2pdf import convert
from os import listdir
from os.path import isfile, join
import ctypes
from tkinter import filedialog
from tkinter import *

root = Tk()
root.withdraw()
ctypes.windll.user32.MessageBoxW(0, "Hit OK to select the file folder with the MS Word DOCX files you wish to convert to PDFs.", "Complete", 0)
word_path = filedialog.askdirectory()
ctypes.windll.user32.MessageBoxW(0, "Hit OK to select the file folder where you want to save your PDFs.", "Complete", 0)
pdf_path = filedialog.askdirectory()
convert(word_path, pdf_path)