0

here is my code, I use python and flask:

pdf = pdfkit.from_url(url, False, options=options)
return send_file(one_file, attachment_filename=file_name,
                     as_attachment=True, mimetype="application/pdf")

size of the pdf file is too large, it's too long to send to user, so I want change the quality of pdf. I use:

options = {'lowquality': True}

but error:

Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/yangle/ksxing/exam/view/exams_mongo.py", line 1537, in export_result_pdf
    pdf = pdfkit.from_url(url, False, options=options)
  File "/usr/lib/python2.7/site-packages/pdfkit/api.py", line 24, in from_url
    return r.to_pdf(output_path)
  File "/usr/lib/python2.7/site-packages/pdfkit/pdfkit.py", line 116, in to_pdf
    raise IOError('wkhtmltopdf reported an error:\n' + stderr.decode('utf-8'))
IOError: wkhtmltopdf reported an error:
Loading pages (1/6)
Error: Failed loading page http://true (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: HostNotFoundError     ] 55%

how to do this?thank you

max
  • 187
  • 1
  • 2
  • 9

2 Answers2

0

you are not passing the options anywhere. Try giving like the following example

options = {
'lowquality': True,
}
pdfkit.from_url('http://google.com', 'out.pdf', options=options)
eshwar m
  • 184
  • 4
  • sorry, my problem.I have pass the option ,and error occur. I have edited my problem.thanks. – max Nov 07 '16 at 08:40
  • check this. http://stackoverflow.com/questions/25894251/how-to-deal-with-contentnotfounderror-when-using-wkhtmltopdf – eshwar m Nov 07 '16 at 09:26
0

If option without value, use None, False or ” for dict value

So try 'lowquality': None instead.

Roy Wang
  • 11,112
  • 2
  • 21
  • 42