Convert Word to PDF - Python

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

Any idea how I can do this?

+3
source share
3 answers

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 see the source code unoconvif you want to do this directly with Python bindings for UNO / OpenOffice COM.

+10
source

Install a PDF printer driver, such as CutePDF.

Use COM automation to start MS Word; open the file, fill in the data, print the file in PDF format.

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

: Word PDF ; ReportLab .

+2

Source: https://habr.com/ru/post/1788230/


All Articles