我想使用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) 在模板“稍后”的框架“正常”(439.275590551 x 685.88976378*) 的第 2 页上太大
parts.append(Image("image.jpg",width=210*mm-doc.rightMargin-doc.leftMargin, height=293*mm-doc.topMargin-doc.bottomMargin))
应该可以。如果你需要保持 image.jpg 的宽高比,你将需要更多的额外工作。