Skip to content

Export to PDF #817

@josephernest

Description

@josephernest

Hi, Congrats for this great project @scanny!

In a .docx file, I need to replace every text {{name}} by a variable in Python, and then export the .docx to PDF. This works:

doc = docx.Document('template.docx')
for paragraph in doc.paragraphs:
    paragraph.text = paragraph.text.replace('{{name}}', 'john')
doc.save('temp.docx')  
# this is very fast until here
# the next line is very slow (3 or 4 seconds for each iteration):
subprocess.call(r"C:\Program Files\LibreOffice\program\soffice.exe --headless --convert-to pdf temp.docx --outdir ." % i)

Is there a faster way, built-in in python-docx, or with another python library, to export a DOCX to PDF?

(I need to do this in batch for thousands of PDF)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions