开发者

Convert Word doc to PDF - Python [closed]

开发者 https://www.devze.com 2023-02-06 21:36 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for gu开发者_Python百科idance. Closed 10 years ago.

I need to fill in a document and then try and convert it into a PDF.

Any idea how I can do this?


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)

You can also look at unoconv's source code if you want to do it directly with the Python bindings for UNO/OpenOffice COM.


Install a PDF printer driver like CutePDF.

Use COM automation to run MS Word; open the file, fill in the data, print the file as a PDF.

Alternatively: convert the Word file into a PDF form; use ReportLab to fill in the form.

Alternatively: print the Word file to a PDF file; use ReportLab to overlay text on the file.


This would be an excellent place to start. It's free as in beer.

0

精彩评论

暂无评论...
验证码 换一张
取 消