3
votes

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 !

1

1 Answers

8
votes

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