将Word doc转换为PDF-Python [英] Convert Word doc to PDF - Python

查看:86
本文介绍了将Word doc转换为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 doc转换为PDF-Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆