我希望将多页PDF转换为单个PNG,这可以通过CLI按convert in.pdf -append out%d.png
每Convert multipage PDF to a single image来实现。
我可以在Python中实现同样的功能吗?我目前有:
with Image(filename=pdf_file_path, resolution=150) as img:
img.background_color = Color("white")
img.alpha_channel = 'remove'
img.save(filename=pdf_file_path[:-3] + "png")
答案 0 :(得分:0)
我无法记住MagickAppendImage
是否已被移植到wand,但您应该能够利用wand.image.Image.composite
。
from wand.image import Image
with Image(filename=pdf_file_path) as pdf:
page_index = 0
height = pdf.height
with Image(width=pdf.width,
height=len(pdf.sequence)*height) as png:
for page in pdf.sequence:
png.composite(page, 0, page_index * height)
page_index += 1
png.save(filename=pdf_file_path[:-3] + "png")