要在使用reportlab构建的报表中插入image.pdf,一种方法是首先使用例如Wand将image.pdf转换为image.jpg:
from wand.image import Image as wandImage
from reportlab.platypus import Image
....
with wandImage(filename='input.pdf') as img:
img.crop(42, 64, 552, 677) # (left, top, width, height)
img.save(filename = "output.jpg")
img = Image("output.jpg", 175.0*mm, 30.0*mm)
img.hAlign = 'CENTER'
rapport.append(img)
...
保存file.jpg并在之后打开此文件似乎不太优雅。是否可以在没有保存步骤的情况下直接使用结果?例如这个白痴代码(不起作用!):
from wand.image import Image as wandImage
from reportlab.platypus import Image
....
with wandImage(filename='input.pdf') as img:
img.crop(42, 64, 552, 677) # (left, top, width, height)
img2 = img.convert('jpeg')
img3 = Image(img2, 175.0*mm, 30.0*mm) # 2508px × 430px
img3.hAlign = 'CENTER'
rapport.append(img3)
...