Python – Microsoft Word to PDF

The following will convert an existing Microsoft Word document into a PDF file type. I find this especially useful for bulk conversions before doing some form of mass mailout.

Find the full source code for this project below:

import comtypes.client
import time
from pathlib import Path

wdFormatPDF = 17
file="Some Document.docx"

if Path(file).is_file():
    out_file="Some PDF.pdf"
    word = comtypes.client.CreateObject('Word.Application')
    word.Visible = True
    doc.SaveAs(out_file, FileFormat=wdFormatPDF) 
    word.Visible = False


Leave a Reply