【问题标题】:Python WAND convert only first PDF pagePython WAND 仅转换第一个 PDF 页面
【发布时间】:2019-03-06 16:09:26
【问题描述】:

我有这段代码,将 pdf 文件作为参数并将其转换为 JPG。我的问题是,当 pdf 有多个页面时,创建这样的图像:test-0.jpg、test-1.jpg 等。

 with Img(filename=args['pdf'] + file, resolution=300) as pic:
        pic.compression_quality = 100
        pic.save(filename='images/test.jpg')

我怎么能说 wand 只转换给定 pdf 的第一页?

谢谢!

【问题讨论】:

    标签: python wand


    【解决方案1】:

    最简单的方法是将[0] 附加到文件名。

    with Img(filename=args['pdf'] + file + '[0]', resolution=300) as pic:
    

    或者您可以使用pic.sequence,但这会更慢,因为它需要对所有页面进行解码。

    with Img(filename=args['pdf'] + file, resolution=300) as pic:
        with Img(pic.sequence[0]) as first_page:
            first_page.save(filename='images/test.jpg')
    

    【讨论】:

      猜你喜欢
      • 2012-04-15
      • 1970-01-01
      • 2011-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-05
      相关资源
      最近更新 更多