2017-03-08 7 views
0

여러 페이지 PDF를/Convert multipage PDF to a single image과 함께 CLI를 통해 얻을 수있는 단일 PNG로 변환하고 싶습니다.imagemagick을 사용하여 Python의 png에 PDF 페이지를 추가하는 방법

파이썬에서 포격하지 않고도 같은 결과를 얻을 수 있습니까? 내가 현재 가지고 :

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")