frappe / frappe

Low code web framework for real world applications, in Python and Javascript
https://frappeframework.com
MIT License
7.02k stars 3.35k forks source link

Error in PDF generation when using glyphicon #10100

Closed paulator closed 7 months ago

paulator commented 4 years ago

Description of the issue

I want to use a glyphicon in my invoice footer (e.g. map marker). Therefore I updated the default letter head and added some HTML to the footer field. When the PDF is generated, I get an error.

Context information (for bug reports)

Output of bench version

v12.6.0

Steps to reproduce the issue

  1. add the following HTML in the footer field of the default letter head: <span class="glyphicon glyphicon-map-marker"></span>
  2. open any document and tick "letter head"
  3. Check the print view of the invoice in ERPNext: You can see the glyphicon
  4. Check the page preview of the invoice in ERPNext, You can see the glyphicon
  5. Check the PDF: The PDF is not generated. An error is generated.

Observed result

PDF generator will throw an error. No PDF is generated.

Expected result

PDF should be generated with the glyphicon.

Stacktrace / full error message

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 62, in application
    response = frappe.api.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 55, in handle
    return frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 22, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 61, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1054, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/print_format.py", line 92, in download_pdf
    frappe.local.response.filecontent = get_pdf(html)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 38, in get_pdf
    filedata = pdfkit.from_string(html, False, options=options or {})
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pdfkit/api.py", line 72, in from_string
    return r.to_pdf(output_path)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pdfkit/pdfkit.py", line 156, in to_pdf
    raise IOError('wkhtmltopdf reported an error:\n' + stderr)
OSError: wkhtmltopdf reported an error:
Exit with code 1 due to network error: ProtocolUnknownError

Additional information

I used the erpnext-docker images from https://github.com/frappe/frappe_docker

paulator commented 4 years ago

I guess, this has to do something with the generated html. When I open a bash in the container and check /tmp directory, I can see some HTML files which have been left by the PDF generator. When I open the HTML, I can find e.g. the following snipped:

src: url('/assets/frappe/css/fonts/glyphicons/glyphicons-halflings-regular.eot');

I guess, wkhtmltopdf cant render it because there is no hostname written in front of the path to the glyphicons css file.

ankush commented 7 months ago

This works now

image