【问题标题】:Unable to generate PDF with wkhtmltopdf on a headless server无法在无头服务器上使用 wkhtmltopdf 生成 PDF
【发布时间】:2018-04-17 14:38:38
【问题描述】:

我有一个使用 CSS 文件的 HTML 文档和从matplotlib 生成的大约十几个 PNG 文件。为了将此 HTML 文档转换为 PDF,我在 AWS EC2 Linux 实例上安装了wkhtmltopdf,采用here 所述的方式。

在命令行上,这是可行的

wkhtmltopdf http://www.google.com output.pdf

但是,下面的 Python sn-p 不起作用。

reportCss = pathlib.Path(os.path.join(cssDir, 'report.css'))
w3Css = pathlib.Path(os.path.join(cssDir, 'w3.css'))
#
options = {
    'page-size': 'A4',
    'dpi': 720,
    'margin-bottom': 5
}
css = [str(reportCss), str(w3Css)]
pdfkit.from_file(htmlFilePath, pdfFilePath, options=options, css=css)

我收到此错误:

QPainter::begin(): Returned false
Traceback (most recent call last):
  File "dailyemail.py", line 55, in <module>
    main()
  File "dailyemail.py", line 44, in main
    pdfFileName = pdfgen.buildPdfDoc()
  File "/home/ubuntu/demo/py/pdfgen.py", line 58, in buildPdfDoc
    pdfkit.from_file(htmlFilePath, pdfFilePath, options=options, css=css)
  File "/home/ubuntu/.local/lib/python2.7/site-packages/pdfkit/api.py", line 49, in from_file
    return r.to_pdf(output_path)
  File "/home/ubuntu/.local/lib/python2.7/site-packages/pdfkit/pdfkit.py", line 181, in to_pdf
    '%s ' %(' '.join(args)),e)
TypeError: not enough arguments for format string

你能告诉我我错过了什么吗?

【问题讨论】:

    标签: python html wkhtmltopdf pdfkit


    【解决方案1】:

    原来 PDF 文件夹不存在。错误消息在中间领先。

    【讨论】:

      猜你喜欢
      • 2014-10-20
      • 2020-04-24
      • 2016-03-03
      • 1970-01-01
      • 2020-06-27
      • 2014-07-03
      • 1970-01-01
      • 2014-07-27
      • 1970-01-01
      相关资源
      最近更新 更多