使用reportlab从图像创建A4大小的PDF

时间:2017-03-10 04:52:38

标签: python image pdf reportlab

我想使用python中的reportlab将A4扫描图像转换为PDF。我写下了波纹管代码,但是我收到了错误。我该如何解决?

from reportlab.lib.pagesizes import A4
from reportlab.lib.units import mm
height, width = A4
doc = SimpleDocTemplate("image.pdf", pagesize=A4)
parts = []
parts.append(Image("image.jpg",width=210*mm, height= 293*mm))
doc.build(parts)

reportlab.platypus.doctemplate.LayoutError:Flowable(595.275590551 x 830.551181102)在第2页的框架'正常'(439.275590551 x 685.88976378 *)的模板'以后'

1 个答案:

答案 0 :(得分:0)

parts.append(Image("image.jpg",width=210*mm-doc.rightMargin-doc.leftMargin, height=293*mm-doc.topMargin-doc.bottomMargin))

应该工作。如果您需要保持image.jpg的长宽比,则需要做一些额外的工作。