I'm using Python 3.8 and docx2pdf 0.1.7. I've been trying for ages to get something something in my script which will convert a docx to a pdf. I've tried all sorts of stuff but nothing has worked for me thus far.
There's a module called docx2pdf which should convert the file I just created but it doesn't seem to work and I can't figure out why that's the case. I tried running it in my script but I also tried running it as a subprocess but neither worked. Documentation of the module is here.
I think this is a pretty unknown module as I couldn't find any answers on the internet so I'm hoping there is someone who knows how to tackle this problem.
This is the code I'm working with:
from docx import Document
from docx.shared import Pt
from tkinter import *
from docx2pdf import convert
root = Tk()
# Then some irrelevant code for this question
def updater()
doc = Document('./Contract.docx')
# Then some code which updates the doc according to the tkinter Entry input
# Save it according to some of the input from the GUI
doc.save('/Users/Jem/Documents/Huurovereenkomsten/Specifiek/{}/contract{}.docx'.format(nospaceadres,
naamhuurder.get()))
# It all works fine until here
convert('/Users/Jem/Documents/Huurovereenkomsten/Specifiek/{}/contract{}.docx'.format(nospaceadres,
naamhuurder.get())) # This should convert it to a pdf with the same name in the same folder
# Some Tkinter GUI code which is also irrelevant for this question
root.mainloop()
But first, it gives me this:
0%| | 0/1 [00:02<?, ?it/s]
Then it opens MS Word on my macbook and tells me it needs a permit / rights to open the docx. I then have to select the document, which gives it the permit to open it. After that, it opens the docx but nothing happens.
After that, it gives me this:
{'input': '/Users/Jem/Documents/Huurovereenkomsten/Specifiek/slotlaan73/contractabc.docx', 'output': '/Users/Jem/Documents/Huurovereenkomsten/Specifiek/slotlaan73/contractabc.pdf', 'result': 'error', 'error': 'Error: Er heeft zich een fout voorgedaan.'}
'Er heeft zich een fout voorgedaan.' is Dutch for: an error has occurred.
Does anyone know why this is happening or what I could do to make it work so that it converts the docx to a pdf?