Rajesh Samui
Rajesh Samui

Reputation: 177

convert pdf to image using pdf url (pdf2image)

images_from_path = convert_from_path(settings.MEDIA_ROOT+'file/some.pdf',100)
images_from_path[0].save(settings.MEDIA_ROOT+'image/'+'a.jpg'))

I can get or save the images like this. How do I use a pdf file-url(https://example.com/xyz.pdf) to get the images?

Upvotes: 2

Views: 4707

Answers (3)

Joolean
Joolean

Reputation: 61

Just summing up to save the next guy some time:

import requests, pdf2image
pdf = requests.get('https://example.com/xyz.pdf', stream=True)
images = pdf2image.convert_from_bytes(pdf.content)

Upvotes: 1

CrashLaker
CrashLaker

Reputation: 61

incrementing @fqrt's answer we need to add stream=True in requests.get

pdf = requests.get('https://example.com/xyz.pdf', stream=True)

Upvotes: 0

fqrt
fqrt

Reputation: 23

Fetch the data using your favourite HTTP library:

import requests, pdf2image
pdf = requests.get('https://example.com/xyz.pdf')
pdf2image.convert_from_bytes(pdf.raw.read())

Upvotes: 2

Related Questions