0

I am trying to generate a pdf report and show it in to the user in the browser. The method i used to do this was to generate the report using docx and then use docx2pdf in order to convert the generated report into pdf format.

My code works perfectly when i host it locally on my machine. However when i try to toast it online via heroku i get the following error:

docx2pdf is not implemented for linux as it requires Microsoft Word to be installed

The weird thing is that i am not using a linux machine. I have tried both safari and google chrome browsers and i get the same result. I find it strange because when i host the site locally, the pdf gets generated and shown in the browser exactly the way i want it. but when i upload to heroku i get the error.

The code that deals with th e conversion is:

def making_a_doc_function(request):

doc = docx.Document()
doc.add_heading("no text")
doc.save('thisisdoc.docx')

#converting the generated docx into a pdf file
convert("thisisdoc.docx", "output.pdf")
pdf = open('output.pdf', 'rb')
response = FileResponse(pdf)

return response
kitchen800
  • 197
  • 1
  • 12
  • 36
  • 1
    Your Heroku server is running Linux, therefore it can't install and use `docx2pdf`. – MattDMo Aug 16 '20 at 21:42
  • @MattDMo thanks for the info i didn't know that, this is the first site im launching so quite new to this.. so what do you think would be my best option to solve this error? I wonder is it possible to remove linux access from heroku? – kitchen800 Aug 16 '20 at 21:48
  • I haven't worked with Heroku in ages, so I don't know if they have an option to run on a Windows server instead of a Linux one. There are also some (free?) APIs available online to convert DOCX files to PDF, so that may be an option for you. – MattDMo Aug 16 '20 at 21:51
  • No worries matt. i will have a look around and see what i come across. – kitchen800 Aug 16 '20 at 21:55
  • @pete800 hope this helps https://stackoverflow.com/questions/50982064/converting-docx-to-pdf-with-pure-python-on-linux-without-libreoffice – Quantum Dreamer Aug 16 '20 at 22:29

0 Answers0