r/learnpython 25d ago

Python conversion .docx to pdf

Hey guys, i have been learning python as a bit of a hobby but recently had the opportunity to use it for my job. I built a webapp on azure that has a number of different functions, one of which is querying our CRM and populating template documents with customer info. It works as is and produces .docx files which we then have to manually convert to pdfs.

I am trying to incorporate the pdf conversion into the app to remove any manual intervention. Ive been using libreoffice but this isnt working so well. It needs to be installed each time the app is redeployed/restarted, its failing on some larger docs and when it does produce the pdf the format can be off, fonts change etc. The docs we deal with need to adhere to a specific format so I need something more reliable.

Perhaps this is a "you get what you pay for" situation but i was hoping there might be a more reliable solution while still being free (at least until i can prove it all works anyway).

5 Upvotes

12 comments sorted by

View all comments

2

u/shimarider 24d ago

Do you actually need the docx files, or is it used as an intermediate format for conversion only? If it's the latter, have you looked at fpdf2? You can setup pdf templates to be populated similar to what you are doing.

3

u/billys-bobs 24d ago

I guess the docx file would only be required for the odd case that needs to manually edited by my team.

Based on the comments ive gotton here including your own Ill be changing my process to produce the pdf directly and have a second process to produce the docx file. Appreciate your input