0

I want to run wkhtmltopdf on heroku, but not able to do so. I am trying to run the wkhtmltopdf.exe and generate pdf, but it shows permission denied.

My folder Structure

15-07-2020  18:06    <DIR>          .
15-07-2020  18:06    <DIR>          ..
15-07-2020  16:40    <DIR>          .idea
15-07-2020  17:33               978 app.py
15-07-2020  17:00                21 Procfile
15-07-2020  17:01               134 requirements.txt
15-07-2020  17:01                12 runtime.txt
15-07-2020  16:34    <DIR>          static
15-07-2020  18:14    <DIR>          templates
15-07-2020  16:33    <DIR>          venv
15-07-2020  17:33    <DIR>          wkhtmltopdf
15-07-2020  18:02    <DIR>          __pycache__
               4 File(s)          1,145 bytes
               8 Dir(s)  49,877,135,360 bytes free

My app.py file

from flask import Flask, render_template, request, make_response

import pdfkit
config = pdfkit.configuration(wkhtmltopdf="./wkhtmltopdf/bin/wkhtmltopdf.exe")
app = Flask(__name__)


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/memo', methods=['GET', 'POST'])
def memo():

    if request.method == 'POST':

        name = request.form.get('name')
        email = request.form.get('email')
        number = request.form.get('number')

        res = render_template('memo.html', name=name, email=email, number=number)
        responsestring = pdfkit.from_string(res, False, configuration=config)
        response = make_response(responsestring)
        response.headers['Content-Type'] = 'application/pdf'
        response.headers['Content-disposition'] = 'inline;filename=test.pdf'
        return response

    else:
        return render_template('index.html')


if __name__ == '__main__':
    app.run()
James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

1

If it's simply a permission denied error, then that simply means that the file doesn't have the required privilege to perform the operation.

You can try to SSH to the Heroku server and add an executable right to the file, like so

sudo chmod a+x /path/to/file/FILENAME

You should also see the related answer here that may fix this with a buildpack.

AzyCrw4282
  • 7,222
  • 5
  • 19
  • 35