2017-03-08 10 views
0

複数ページのPDFをConvert multipage PDF to a single imageconvert in.pdf -append out%d.pngのCLIで実現できる単一のPNGに変換したいのですが、imagemagickでpythonのpngにpdfのページを追加するには

私は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") 
関連する問題