I have created an app with Flask which takes some user inputs, calculates them, and then generates the pdf out of that data.
I have followed this and getting the same error: How to get WKHTMLTOPDF working on Heroku?
Here is my code:
@app.route('/download')
def download():
credit_hours = aaa['Credit Hours']
rendered = render_template("report2.html", credit_hours=credit_hours)
def _get_pdfkit_config():
if platform.system() == 'Windows':
return pdfkit.configuration(wkhtmltopdf=os.environ.get('WKHTMLTOPDF_BINARY', 'C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'))
else:
WKHTMLTOPDF_CMD = subprocess.Popen(['which', os.environ.get('WKHTMLTOPDF_BINARY', 'wkhtmltopdf')], stdout=subprocess.PIPE).communicate()[0].strip()
return pdfkit.configuration(wkhtmltopdf=WKHTMLTOPDF_CMD)
pdf = pdfkit.from_string(rendered, False, configuration=_get_pdfkit_config())
response = make_response(pdf)
response.headers['Content-Type'] = 'application/pdf'
response.headers['Content-Disposition'] = f'inline; filename={ag_number} GPA Report.pdf'
return response
Requirements.txt:
git+git://github.com/johnfraney/wkhtmltopdf-pack.git
pdfkit==0.6.1
Error, I am getting is "Internal Server Error" on Heroku.
The above code is working perfectly on my local machine. But when I deploy it to heroku I get
Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.