我使用的是 Python 2.7.14。
我目前正在开发一个程序,该程序可以对 Word 文档上的某些信息进行调整。这个目标已经实现,但我在将 .docx 文档转换为 .pdf 时遇到了麻烦。
我想使用此链接中的代码:.doc to pdf using python
但是,我在导入 comtypes.client
时遇到错误
Traceback (most recent call last):
File "C:\Python27\comtypes.py", line 2, in <module>
from comtypes.client import CreateObject, GetActiveObject
File "C:\Python27\comtypes.py", line 2, in <module>
from comtypes.client import CreateObject, GetActiveObject
ImportError: No module named client
看起来我确实已经使用 pip install comtypes
安装了 comtypes。
这是我想用来将 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()
最佳答案
使用pycharm作为IDE。 只需右键单击即可安装您的软件包。 或者使用
pip install comtypes
关于python - 没有名为 client 的模块,将 docx 转换为 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50021688/