使用python将word文件转换成PDF,代码如下:
def convertDocxToPDF(infile,outfile):
wdFormatPDF = 17
word = comtypes.client.CreateObject('Word.Application')
doc = word.Documents.Open(infile)
doc.SaveAs(outfile, FileFormat=wdFormatPDF)
doc.Close()
word.Quit()
但发现速度很慢,经过排查,发现word = comtypes.client.CreateObject('Word.Application')
这一句执行需要近20s,在执行批量转换时,为了提高效率,能否在内存中生成一个word,每次转换时都在这个word上进行?请问技术上如果可以实现应该怎么写代码?
你机器本身启动 word 就太慢了吧。
以前处理类似场景,我是用 win32com 的。里面有个
Dispatch
可以得到一个实例。https://groups.google.com/for...
7年前的代码。