首页 > 解决方案 > .doc 到 pdf 使用 python 错误

问题描述

我正在尝试使用python将word文档转换为PDF。目前在python 3.8上。

.doc 到 pdf 使用 python

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()

上面的代码回答了我的问题,但是当我将它部署到 VM 并使用调度程序远程运行它时,它只能在我的机器上运行,我得到以下错误

File "File Name", line 10, in <module>                                   
word = comtypes.client.CreateObject('Word.Application')
File "Path", init__.py",line1225, in CoCreateInstance
----------------------------------------------------
File"_ctypes/callproc.c",line 930, in getResult
PermissionError:[WinError -2147024891] Access is denied

仅供参考,单词已安装在 VM 上

谢谢

标签: python

解决方案


推荐阅读