Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wkhtmltopdf exited with non-zero code {0} django html to pdf on server

I am converting html to pdf using wkhtmltopdf. But I am getting an error

raise IOError("wkhtmltopdf exited with non-zero code {0}. error:\n{1}".format(exit_code, stderr.decode("utf-8")))
IOError: wkhtmltopdf exited with non-zero code 1. error:
xvfb-run: error: Xvfb failed to start

My code is:

    f = open('cover_page.html', 'w')
    cap_type = indi_user.cap_type
    message = """<html>
    <head></head>
    <body><h1 style="font-size:150px;margin-top: 450px;">%s</h1></body>
    </html>""" % (cap_type.encode('utf-8').strip())
    f.write(message)
    f.close()
    pdfkit.from_url('cover_page.html', 'cover_page.pdf')
    os.remove("cover_page.html")
    final_pdf_list.insert(0, 'cover_page.pdf')
    to_be_removed.append("cover_page.pdf")
    pypdftk.concat(final_pdf_list, str(destination))

I don't know what wrong I am doing wrong there.

I tried everything but still stuck on the same error.

like image 941
Wagh Avatar asked Oct 24 '25 15:10

Wagh


1 Answers

Do you have XVFB installed ? if not you should install it by package manager, for example apt-get install xvfb. Otherwise get through the /tmp/xvfb-error.log file, to get specific xvfb error message.

like image 127
mdargacz Avatar answered Oct 27 '25 04:10

mdargacz