Getting the error below when I try to run wkhtmltopdf in a docker environment.
subprocess.CalledProcessError: Command '['wkhtmltopdf', '--encoding', 'utf8', '--margin-top', '10', '--quiet', '/tmp/wkhtmltopdf85qv7fvc.html', '-']' died with <Signals.SIGABRT: 6>.
The code is seen below.
It is working in an Ubuntu 16.04 vagrant machine. However, when I move it to a docker environment, it fails with the error above. At first I was using a Python3.6 image then changed to an Ubuntu 16.04 image thinking that maybe wkhtmltopdf requires a fuller linux environment. But still no luck.
from django.http import HttpRequest
from wkhtmltopdf.views import PDFTemplateResponse
def generate_invoice_pdf(download_pdf=False, **kwargs):
"""
Render html to PDF
"""
file_name = kwargs['file_name']
template = kwargs['template']
context = {
"first_Name": "John",
"last_name": "Doe"
}
# Create request object
request = HttpRequest()
params = {
'request': request,
'template': template,
'filename': os.path.basename(file_name),
'context': context,
'cmd_options': {'margin-top': 10, },
'show_content_in_browser': True
}
response = PDFTemplateResponse(**params)
# write the rendered content to a file
with open(file_name, "wb") as f:
f.write(response.rendered_content) # Part throwing the error
if download_pdf:
return response
else:
msg = 'PDF Generated: {}'.format(file_name)
return msg