3.4 word 转 pdf

from win32com.client import gencache
from win32com.client import constants

def createPdf(wordPath, pdfPath):
    """
    word 转 pdf
    :param  wordPath: word 文件路径
    :param  pdfPath: 生成pdf的文件路径
    """
    word = gencache.EnsureDispatch('Word.Application')
    doc = word.Documents.Open(wordPath, ReadOnly=1)
    doc.ExportAsFixedFormat(pdfPath, constants.wdExportFormatPDF, Item=constants.wdExportDocumentWithMarkup,
                            CreateBookmarks=constants.wdExportCreateHeadingBookmarks)
    word.Quit(constants.wdDoNotSaveChanges)

if __name__ == '__main__':
    # 文件路径填写绝对路径
    createPdf('D:/git-python/办公自动化/files/违章通知书.docx', 'D:/git-python/办公自动化/files/违章通知书.pdf')