Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Word doc to PDF - Python [closed]

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

Any idea how I can do this?

like image 895
RadiantHex Avatar asked Dec 07 '22 23:12

RadiantHex


1 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 look at unoconv's source code if you want to do it directly with the Python bindings for UNO/OpenOffice COM.

like image 145
Rosh Oxymoron Avatar answered Dec 21 '22 19:12

Rosh Oxymoron