0

I have the following code to extract PDF to JPG. I had to resize the img because of the large size, I loose the PDF original format (A4, A3 etc..) :

with Img(filename=pdfName, resolution=self.resolution) as document:
reader = PyPDF2.PdfFileReader(pdfName.replace('[0]', ''))
for page_number, page in enumerate(document.sequence):
    pdfSize = reader.getPage(page_number).mediaBox
    width   = pdfSize[2]
    height  = pdfSize[3]
    with Img(page, resolution=self.resolution) as img:
        # Do not resize first page, which used to find useful informations
        if not get_first_page:
            img.resize(int(width), int(height))
        img.compression_quality = self.compressionQuality
        img.background_color    = Color("white")
        img.alpha_channel       = 'remove'
        if get_first_page:
            filename = output
        else:
            filename = tmpPath + '/' + 'tmp-' + str(page_number) + '.jpg'
        img.save(filename=filename)

So, for each page, I read the PDF size, and resize the output made with wand. But my problem is the quality of jpg, which is really poor...

My resolution is 300 (I try with upper value, without succes) and compressionQuality is 100

Any ideas ?

Thanks

Nathan Cheval
  • 773
  • 2
  • 7
  • 32

0 Answers0