0

I want to convert my word .docx file to pdf using Python.

import os
import pypandoc
from django.http import FileResponse

newdir = os.path.abspath(os.path.join(os.path.dirname(__file__)))
if not os.path.exists(newdir):
    os.makedirs(newdir)
print(newdir)

file_name = os.path.join(newdir, 'test.docx')
pdf_filename = file_name.split(".docx")[0]
pdf_file = pypandoc.convert_file(file_name, 'pdf', format='docx', outputfile=pdf_filename + ".pdf", extra_args=['--pdf-engine=pdflatex'])
pdf = open(pdf_filename + ".pdf", 'rb')
response = FileResponse(pdf)
return response

I have already installed pdflatex and pylatex but I'm getting the error- RuntimeError: Pandoc died with exitcode "47" during conversion: pdflatex not found. Please select a different --pdf-engine or install pdflatex

ninjacode
  • 318
  • 2
  • 18
  • When you say "doc", are you referring to the legacy `.doc` format used by Microsoft Word 97-2003 or are you also including the current `.docx` format used by Word and other programs today? – Locke Nov 25 '21 at 05:48
  • I'm referring to .docx – ninjacode Nov 25 '21 at 05:53

0 Answers0