我有这段代码,将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')
我怎么能说魔杖只转换给定pdf的第一页?
谢谢 !
最简单的方法是将[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')