【发布时间】:2020-11-10 22:45:13
【问题描述】:
我在 Windows 上使用 pdfkit 将 HTML URL 转换为 pdf 文件并将其作为响应发送。我在我的系统上安装了 wkhtmltopdf,因为它是使用 pdfkit 的依赖项。我正在将存储在我的驱动器中的 wkhtmtopdf 的路径添加到 pdfkit 的配置值中。一切正常,但我担心的是,路径在我的应用程序中是硬编码的,现在如果我想对我的应用程序进行 dockerize 并将其部署在亚马逊上会发生什么。 这是我正在使用的代码:
path_wkthmltopdf = 'C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
pdf = pdfkit.from_url(order["invoice_url"], False, configuration=config)
response = HttpResponse(pdf, content_type='application/pdf')
filename = "Invoice_" + order["order_id"] + "_" + datetime.today().strftime('%d-%m-%Y') + ".pdf"
content = "attachment; filename=" + filename
response['Content-Disposition'] = content
return response
有没有更好的方法来处理这个 HTML URL 到 PDF 的转换?
【问题讨论】:
-
将 .exe 复制到您的项目中。更好的方法是在 docker config 中执行 wget+unzip。(即安装命令)
-
你的意思是,把wkhtmltopdf的.exe文件复制到我的项目中,然后一边dockerizing一边安装?这很好,但是我在代码中硬编码的配置路径呢?
标签: python django amazon-ec2 wkhtmltopdf pdfkit