使用wkhtmltopdfpdfkit的Python包装器出现问题对象没有属性'配置和其他

问题描述

我遇到的问题与此帖子非常相似:pdfkit - python : 'str' object has no attribute decode

我正在通过Web应用程序运行python脚本。

使用python 3.6版pip3安装后导入pdfkit。

import pdfkit

def pdfkit(source,method):

if method == "string":

    try:
        options = {
            'page-size': 'A4','margin-top': '0.75in','margin-right': '0.75in','margin-bottom': '0.75in','margin-left': '0.75in',}
        config = pdfkit.configuration(wkhtmltopdf=bytes("/usr/local/bin/wkhtmltopdf",'utf8'))
        pdf = pdfkit.from_string(source,False,options=options,configuration=config)
        return pdf

    except Exception as e:
        return str(e)
else:
    return "Error:  Not yet Supported"

我按照UBUNTU 20.04的这些说明安装了wkhtmltopdf。它说这些是“无头的”,可以从命令行执行。实际上,在使用pdfkit包装器时确实可以,但是当我尝试通过python脚本本身运行时,它是行不通的。

我遇到的错误之一是:

{
   "pdf": "'function' object has no attribute 'configuration'"
}

除其他外,如果删除配置,则类似from_string。

只是想知道我是否需要导入其他模块,或者是否需要在系统上使用其他版本的wkhtmltopdf。

我需要获取其他二进制文件,还是按照此处的说明进行操作?这很令人困惑,因为有多种安装方法,包括CLI,.deb软件包和使用GitHub上的信息。谢谢。

wkhtmltopdf/packaging

wkhtmltopdf for UBUNTU

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)