2017-03-08 50 views
0

我想将多页PDF转换为单个PNG,可以通过CLI以convert in.pdf -append out%d.png(根据Convert multipage PDF to a single image)实现。如何使用imagemagick将python页面附加到Python中的png

我可以在没有脱壳的情况下在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

我不记得,如果MagickAppendImage已经被移植到,但你应该能够利用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") 
相关问题