I\'m dealing with a problem trying to develop a web-app, part of which converts uploaded docx files to pdf files (after some processing). With python-docx and o
Another one you could use is libreoffice, however as the first responder said the quality will never be as good as using the actual comtypes.
anyways, after you have installed libreoffice, here is the code to do it.
from subprocess import Popen
LIBRE_OFFICE = r"C:\Program Files\LibreOffice\program\soffice.exe"
def convert_to_pdf(input_docx, out_folder):
p = Popen([LIBRE_OFFICE, '--headless', '--convert-to', 'pdf', '--outdir',
out_folder, input_docx])
print([LIBRE_OFFICE, '--convert-to', 'pdf', input_docx])
p.communicate()
sample_doc = 'file.docx'
out_folder = 'some_folder'
convert_to_pdf(sample_doc, out_folder)