【问题标题】:How to append pages of a pdf to a png in python with imagemagick如何使用imagemagick将pdf页面附加到python中的png
【发布时间】:2017-07-28 09:57:19
【问题描述】:

我想将多页 PDF 转换为单个 PNG,这可以通过 CLI 使用 convert in.pdf -append out%d.png per 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")

【问题讨论】:

    标签: python imagemagick wand magickwand


    【解决方案1】:

    我不记得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")
    

    【讨论】:

      猜你喜欢
      • 2022-10-04
      • 2022-01-22
      • 2014-05-12
      • 1970-01-01
      • 2014-10-02
      • 2016-11-02
      • 2011-07-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多