Search code examples
pythondjangolinuxwkhtmltopdfdjango-wkhtmltopdf

Django wkhtmltopdf loading stuck


same issue. Just checking if it has been solved. More context: I'm using django-wkhtmltopdf 3.3.0 and wkhtmltopdf 0.12.5 (with patched qt) on ubuntu.

options = {
    'title': "PDF Title",
    'page-size': 'A4',
    'orientation': 'portrait',
    'margin-top': '20mm',
    'margin-right': '10mm',
    'margin-bottom': '20mm',
    'margin-left': '10mm',
    'load-error-handling': 'ignore',
    'quiet': None,
    'enable-local-file-access': True,
    'header-spacing': 5,
    'footer-spacing': 5,
}

When I run this command, my server gets stuck with this message:

Loading pages (1/6)
[=================>                                          ] 29%

If I ctrl C my server, I can see the command that was running:

/usr/local/bin/wkhtmltopdf --enable-local-file-access --encoding utf8 --footer-spacing 5 --footer-html /tmp/wkhtmltopdfap_vk62a.html --header-spacing 5 --header-html /tmp/wkhtmltopdfhfdro6i1.html --load-error-handling ignore --margin-bottom 20mm --margin-left 10mm --margin-right 10mm --margin-top 20mm --orientation portrait --page-size A4 --title "PDF Title" /tmp/wkhtmltopdfku94woo9.html - 

The latter works fine when execute on bash (or python shell).

Thank you random stack overflow shell deities.


Solution

  • Seems the problem is from static files loading.

    wkhtmltopdf tries loading the static files from "localhost:8000/static" but that port is already busy, awaiting to respond to the query calling wkhtmltopdf. Some sort of mutual exclusion.

    Edit: I fixed this by adding moving the static files to an nginx server on port 8081, and serving them from there.