1

I want to covert image-based PDF to image(.png/.jpg) file in Python, so I can further use this image for exacting tabular data form it. I don not want to run the code from command line.

I am currently using Python 3.7.1 version and Pycharm IDE.

I have tried the code provided on stackoverflow but nothing works, it runs but unable to extract image form image-based PDF file. Below is the link for it. Extracting images from pdf using Python

Also, tried the code from dzone.com, below is the link but nothing works https://dzone.com/articles/exporting-data-from-pdfs-with-python

Below are the image-based PDF file links:

link1: https://www.molex.com/pdm_docs/sd/190390001_sd.pdf

link2: https://www.te.com/commerce/DocumentDelivery/DDEController?Action=showdoc&DocId=Customer+Drawing%7FDT04-12PX-C015%7F-%7Fpdf%7FEnglish%7FENG_CD_DT04-12PX-C015_-.pdf%7FDT04-12PA-C015

Please suggest any solution for this.

4
  • 1
    Does this answer your question? Convert PDF to Image using Python Commented Apr 24, 2020 at 5:29
  • 1
    stackoverflow.com/questions/46184239/… Commented Apr 24, 2020 at 5:30
  • thank you joe, this link is very helpful to me, this is what i was searching for long time Commented Apr 24, 2020 at 7:25
  • If it is a solution to your question please close / delete it. Commented Apr 24, 2020 at 9:03

1 Answer 1

4

The pdf2image library converts pdf to images. As looking at your pdfs they are just images nothing else, you can convert the page to image

Install

pip install pdf2image

Once installed you can use following code to get images.

from pdf2image import convert_from_path
pages = convert_from_path('pdf_file', 500)

# Saving pages in jpeg format

for page in pages:
    page.save('out.jpg', 'JPEG')
Sign up to request clarification or add additional context in comments.

3 Comments

hello kuldeep, I am getting above error while running the code, I have also installed the pdf2image python module, but still getting this error
You will need poppler, check here: github.com/Belval/pdf2image
thank you kuldeep, your code is now working fine after installing poppler

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.