我正在尝试用以下代码将docx文件转换为pdf
import sys
import os
import comtypes.client
wdFormatPDF = 17
in_file = os.path.abspath(sys.argv[1])
out_file = os.path.abspath(sys.argv[2])
word = comtypes.client.CreateObject('Word.Application')
doc = word.Documents.Open(in_file)
doc.SaveAs(out_file, FileFormat=wdFormatPDF)
doc.Close()
word.Quit()
它抛出了一个错误
ImportError: cannot import name COMError
我已经安装了comtypes包。
我对python很陌生,我不知道如何解决这个问题。
[编辑]
堆栈跟踪
Traceback (most recent call last):
File "converttopdf.py", line 3, in <module>
import comtypes.client
File "/usr/local/lib/python2.7/dist-packages/comtypes-1.1.2-py2.7.egg/comtypes/__init__.py", line 23, in <module>
from _ctypes import COMError
ImportError: cannot import name COMError
目前没有回答
相关问题 更多 >
编程相关推荐