docker 환경에서 wkhtmltopdf를 실행하려고하면 아래 오류가 표시됩니다.docker 환경에서 wkhtmltopdf의 프로세스 오류
subprocess.CalledProcessError: Command '['wkhtmltopdf', '--encoding', 'utf8', '--margin-top', '10', '--quiet', '/tmp/wkhtmltopdf85qv7fvc.html', '-']' died with <Signals.SIGABRT: 6>.
코드는 아래에 볼 수 있습니다.
우분투 16.04의 방랑 기계에서 작동합니다. 그러나, 그것을 도커 환경으로 옮기면 위의 오류로 실패합니다. 처음에는 Python3.6 이미지를 사용한 다음 우분투 16.04 이미지로 변경하여 wkhtmltopdf가 완전한 리눅스 환경을 필요로한다고 생각했습니다. 그러나 여전히 운이 없다.
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