【问题标题】:pdfkit- Warning: Blocked access to filepdfkit-警告:阻止访问文件
【发布时间】:2020-07-09 12:16:53
【问题描述】:

在我的 HTML 文件中使用本地图像时,我在使用 pdfkit 库将 HTML 转换为 pdf 时遇到错误(阻止对文件的访问)。 如何在我的 HTML 文件中使用本地图像?

【问题讨论】:

    标签: python pdfkit


    【解决方案1】:

    我遇到了同样的问题。我通过在 pdfkit.from_file() 中添加“启用本地文件访问”选项来解决它。

    options = {
      "enable-local-file-access": None
    }
    
    pdfkit.from_file(html_file_name, pdf_file_name, options=options)
    

    【讨论】:

    • 使用 wkhtmltopdf 0.12.6 和 pdfkit 0.6.1,这个选项适合我,而 kimbespo 没有。
    【解决方案2】:

    Pdfkitwkhtmltopdf 的python 包装器。它似乎继承了最近版本中 wkhtmltopdf 的默认行为,现在 blocks local file access 除非另有说明。

    但是,由于 pdfkit 允许您指定 any of the original wkhtmltopdf options,您应该能够通过传递 enable-local-file-access 选项来解决此问题。

    按照 pdfkit 网站上的示例,可能看起来像这样:

    options = {
        "enable-local-file-access": ""
    }
    
    pdfkit.from_string(html, output_path=False, options=options)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-16
      • 2011-04-09
      相关资源
      最近更新 更多