Python-使用 docx2pdf import Convert 将 docx 转换为 pdf,但抛出错误 AttributeError: Word.Application.Documents

发布于 2025-01-11 06:54:58 字数 345 浏览 3 评论 0原文

我正在尝试使用转换方法将 .docx 转换为 pdf。早些时候它可以工作,但现在我在输出中看到错误。请建议

#Converting docx to pdf format
from docx2pdf import convert

# Bulk Conversion
convert(r'C:\Users\ABC\',r'C:\Users\ABC\New\')

输出:AttributeError:Word.Application.Documents 在此处输入图片说明

i am trying to convert to .docx to pdf using convert method. Earlier it was working but now i see error in the output.Kindly suggest

#Converting docx to pdf format
from docx2pdf import convert

# Bulk Conversion
convert(r'C:\Users\ABC\',r'C:\Users\ABC\New\')

Output:AttributeError: Word.Application.Documents
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叹梦 2025-01-18 06:54:58

看来您遇到了路径问题,从文档中我可以看到

from docx2pdf import convert

convert("input.docx")
convert("input.docx", "output.pdf")
convert("my_docx_folder/")

您可以尝试更改路径吗?

It looks like you are having a path issue, from the documentation I can see

from docx2pdf import convert

convert("input.docx")
convert("input.docx", "output.pdf")
convert("my_docx_folder/")

Can you try to maybe change the path?

温暖的光 2025-01-18 06:54:58

不要仅导入 convert 函数,导入整个类 docx2pdf。我的猜测是它使用的 win32 依赖项在运行时获取 .docx 文件属性。因此,仅在批量转换时导入 convert 可能会导致冲突。

我最近在 docx2pdf 之上构建了一个用于批量转换的 cli rocketpdf,并且我必须导入整个类才能操作 tqdm 等进程代码>.

Do not import only convert function, import the whole class docx2pdf. My guess is the win32 dependency it uses gets the .docx file attributes on runtime. So importing convert only on bulk conversions may be causing the conflict.

I recently built a cli rocketpdf for bulk conversions like this on top of docx2pdf and I had to import the whole class in order to manipulate some processes like tqdm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文