【发布时间】:2020-04-23 20:46:46
【问题描述】:
我正在查看以下问题的答案:Insert Base64 image to pdf using pyfpdf
这里建议的答案是覆盖现有的load_resource 方法。
我所做的是
class EnhancedPdf(FPDF):
def load_resource(self, reason, filename):
if reason == "image":
if filename.startswith("data"):
f = filename.split("base64,")[1]
f = base64.b64decode(f)
f = BytesIO(f)
return f
else:
return super().load_resource(reason, filename)
但是,Pycharm 突出显示超级调用,并显示消息“类“FPDF”的未解析属性引用“load_resource”
在我的命令行中,我运行了命令
from fpdf import FPDF
dir(FPDF)
查看这个列表,我看到load_resource 函数确实不是一个列出的方法。因此我的问题是为什么load_resource 函数不可见?
【问题讨论】:
-
也许您正在使用不同版本的 pyfpdf,其中 load_resource() 不再存在。
-
你使用的是 Python 2 还是 Python 3 ?
-
在最新版本中肯定有
def load_resource(self, reason, filename)在第 1774 行 -
@ChrisDoyle 我想我正在使用最新版本。我几天前使用 pip 安装了。版本号 1.7.2
-
@Cucu 我需要卸载旧的 fpdf 包吗?
标签: python fpdf class-attributes