Python WAND convert only first PDF page
Asked Answered
C

1

5

I have this piece of code, taking a pdf file as argument and convert it to JPG. My problem is, when the pdf have more than one page wand create image like this : test-0.jpg, test-1.jpg etc..

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

How could I say to wand to just convert the first page of the given pdf ?

Thanks !

Caracal answered 6/3, 2019 at 16:9 Comment(0)
P
11

Easiest way would be to append [0] to the filename.

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

Or you can use pic.sequence, but that would be slower as it would require all the pages to be decoded.

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')
Perfection answered 6/3, 2019 at 20:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.