Python: Word to Pdf 错误 (OSError: [WinError -2147221005] Invalid class string )

问题描述

我正在尝试使用此代码将 word 文件转换为 pdf 文件:但它给了我这个无法理解的错误(OSError: [WinError -2147221005] Invalid class string)我检查了这个 answer 但我没有不明白答案

import os
import comtypes.client

wdFormatPDF = 17



in_file = os.path.abspath("C:\\Users\\somename\\Desktop\\tests\\sad.doc")
out_file = os.path.abspath("C:\\Users\\somename\\Desktop\\tests\\sad.pdf")

word = comtypes.client.CreateObject('Word.Application')

doc = word.Documents.Open(in_file)

doc.SaveAs(out_file,FileFormat=wdFormatPDF)

doc.Close()

word.Quit() 

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)