I want to save a doc file as pdf using python, I tried so many solution but I couldn’t find the right one.
This is my code, I tried to make the output file as a pdf file but it didn’t open. Any help is highly appreciated :
JavaScript
x
13
13
1
def replace_string(filenameInput, filenameOutput):
2
3
doc = Document(filenameInput)
4
5
for p in doc.paragraphs:
6
for d in J['data']:
7
if p.text.find(d['variable']) >= 0:
8
p.text = p.text.replace(d['variable'], d['value'])
9
10
doc.save(filenameOutput)
11
12
replace_string('test.docx', 'test2.pdf')
13
Advertisement
Answer
JavaScript
1
6
1
import docx2pdf
2
def convert_file(filenameInput, filenameOutput):
3
docx2pdf.convert(filenameInput, filenameOutput)
4
5
convert_file('test.docx', 'test2.pdf')
6
There is a Python package called docx2pdf. You can use it to simply convert docx file into pdf!
There is a link to the package! https://pypi.org/project/docx2pdf/