我正在使用reportlab 生成一些pdf。我需要附加一些图像。旧脚本依赖于已弃用的库将这些图像的 pdf 版本添加到新的 pdf 中,但我认为我应该能够将它们添加为 png,如下所示:
doc = SimpleDocTemplate("GBD Country Report - " + country_name + ".pdf",
pagesize=letter,
rightMargin=0.25 * inch, leftMargin=0.25 * inch,
topMargin=0.75 * inch, bottomMargin=0.25 * inch)
elements = []
elements.append(Image(data_dir + 'figure1.png'), width=1, height=1)
doc.build(elements)
但是,当我这样做时,我得到了这个错误:reportlab.platypus.doctemplate.LayoutError: Flowable <Image at 0x10bd6ae10 frame=cod filename=.../figure1.png>(28.346456692913385 x 612.0) too large on page 1 in frame 'cod'(475.2 x 90.0*) of template 'FirstPage'
。我尝试多次添加更改宽度和高度参数,但没有帮助。有什么方法可以动态修改图表图像的宽度和高度,使其适合框架/模板?