ドッカー環境でwkhtmltopdfを実行しようとすると、以下のエラーが表示されます。ドッカー環境でのwkhtmltopdfのサブプロセスエラー
subprocess.CalledProcessError: Command '['wkhtmltopdf', '--encoding', 'utf8', '--margin-top', '10', '--quiet', '/tmp/wkhtmltopdf85qv7fvc.html', '-']' died with <Signals.SIGABRT: 6>.
コードを以下に見られます。
これはUbuntu 16.04迷惑メールマシンで動作しています。しかし、ドッカー環境に移動すると、上記のエラーで失敗します。最初はPython3.6のイメージを使用していましたが、おそらくwkhtmltopdfがより充実したLinux環境を必要とすると思われるUbuntu 16.04イメージに変更されました。しかし、まだ運がありません。
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
'SIGABRT'は、すべてが一緒にクラッシュしていることを示している可能性があります。コンテナの中に入って、手動でコマンドを実行し、結果が何であるかを確認してください。 –
wkhtmlが正しくインストールされています。 'root#wkhtmltopdf -V'は' wkhtmltopdf 0.12.2.4'です。たとえば、コンソールからGoogleページをPDFに変換します。コンソールから 'generate_invoice_pdf'コマンドを実行すると、同じエラーが発生する – lukik