将 Word 文档转换为 PDF - Python [英] Convert Word doc to PDF - Python
本文介绍了将 Word 文档转换为 PDF - Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要填写一个文档,然后尝试将其转换为 PDF.
I need to fill in a document and then try and convert it into a PDF.
知道我该怎么做吗?
推荐答案
如果 OpenOffice 在系统上可用,您可以使用它.
You can use OpenOffice if it is available on the system.
import subprocess
import shutil
input_filename = 'input.doc'
output_filename = 'output.pdf'
p = subprocess.Popen(['unoconv', '--stdout', input_filename], stdout=subprocess.PIPE)
with open(output_filename, 'w') as output:
shutil.copyfileobj(p.stdout, output)
如果您想直接使用 UNO/OpenOffice COM 的 Python 绑定执行此操作,也可以查看 unoconv
的源代码.
You can also look at unoconv
's source code if you want to do it directly with the Python bindings for UNO/OpenOffice COM.
这篇关于将 Word 文档转换为 PDF - Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文