0

I have the following function to convert PDF to images :

from wand.image import Image as Img
    with Img(filename=pdfName, resolution=self.resolution) as pic:
    pic.compression_quality = self.compressionQuality
    pic.background_color    = Color("white")
    pic.alpha_channel       = 'remove'
    pic.save(filename='full_' + random + '-%03d.jpg')

If the PDF is multi page the JPG files are like this :

file-000.jpg, file-001.jpg

My question is, is it possible to have a cpt starting at 1 ?

file-001.jpg, file-002.jpg

Thanks in advance

Nathan30
  • 689
  • 2
  • 8
  • 29

1 Answers1

2

Update

Another option is to set the Image.scene

from wand.image import Image as Img
from wand.api import library

with Img(filename=pdfName, resolution=self.resolution) as pic.
    # Move the internal iterator to first frame.
    library.MagickResetIterator(pic.wand)
    pic.scene = 1
    pic.compression_quality = self.compressionQuality
    pic.background_color    = Color("white")
    pic.alpha_channel       = 'remove'
    pic.save(filename='full_' + random + '-%03d.jpg')

Original

The only thing I can think of is putting an empty image on the stack before reading.

with Img(filename='NULL:') as pic:
    pic.read(filename=pdfName, resolution=self.resolution)
    pic.compression_quality = self.compressionQuality
    pic.background_color    = Color("white")
    pic.alpha_channel       = 'remove'
    pic.save(filename='full_' + random + '-%03d.jpg')

This would put a file-000.jpg, but it would be empty, and you can quickly remove it with os.remove()

emcconville
  • 23,800
  • 4
  • 50
  • 66