Pywin32 save .docx as pdf

一曲冷凌霜 提交于 2019-12-05 02:16:34
James Mills

There are a couple of nice libraries to handle this task:

There is also an example of doing exactly this in this ActiveState Recipe Convert Microsoft Word files to PDF with DOCXtoPDF


If you insist on using Windows API(s) there is also an example of doing this via win32com in this recipe Convert doc and docx files to pdf


You could also do this using comtypes (Thanks to .doc to pdf using python)

Example:

import os
import sys


import comtypes.client


wdFormatPDF = 17


def covx_to_pdf(infile, outfile):
    """Convert a Word .docx to PDF"""

    word = comtypes.client.CreateObject('Word.Application')
    doc = word.Documents.Open(infile)
    doc.SaveAs(outfile, FileFormat=wdFormatPDF)
    doc.Close()
    word.Quit()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!