Home > Blockchain >  Convert PDF of single page to image
Convert PDF of single page to image

Time:03-25

I am trying to convert pdf to an image using the following code

from pdf2image import convert_from_path

pages = convert_from_path('Sample.pdf', 50, poppler_path=r'C:\Program Files\poppler-20.11.0\bin')
pages[0].save('OutImage.jpg', 'JPEG')

The code is working but I am trying to control the output image to make its size 1389 x 1965 Can you guide me, please?

CodePudding user response:

Found size parameter of convert_from_path function

size -> Size of the resulting image(s), uses the Pillow (width, height) standard

Example of using it:

from pdf2image import convert_from_path

pages = convert_from_path("eng.pdf", 50, size=(1389, 1965))
pages[0].save("OutImage.jpg", "JPEG")
$ file OutImage.jpg
OutImage.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 1389x1965, components 3

  • Related