1

I want to convert PDF file to image file (.jpg, or .png ...). I have found this solution but I always get an error:

from pdf2image import convert_from_path 

pages = convert_from_path('sample.pdf', 500) # I have tried with full path, and with different num of pages

The error that I get:

pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?

How can I fix this?

If there is any other way to convert pdf to .jpg please let me know.

taga
  • 3,537
  • 13
  • 53
  • 119

1 Answers1

0

Download the Poppler method from the below link

  1. Poppler for Windows

  2. How to Install poppler-utils in Ubuntu/Linux

  3. sudo apt-get install poppler-utils sudo code for ubuntu

  4. Download the Poppler package and extract it. open the Poppler folder and copy the bin folder path to poppler_path variable (for windows only, no need for linux)

  5. If system is windows/Linux Using platform module returns a string that displays the name of the operation system on the current device being used to run the program.

    from pdf2image import convert_from_path, convert_from_bytes
    import platform
    
    if platform.system() == "Windows":     
        pages = convert_from_path(r"C:\ABC\xyz.pdf", 500,poppler_path= r'C:\ABC\poppler-0.68.0\bin')
    elif if platform.system() == "Linux":
        pages = convert_from_path(r"C:\ABC\xyz.pdf", 500)
    for page in pages:
        page.save(r"C:\ABC\xyz.pdf".lower().replace(".pdf",".jpg"),'JPEG')
    
thrinadhn
  • 1,673
  • 22
  • 32