Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I convert PDF blob to image using Python and Wand?

Tags:

python

wand

I'm trying to convert a PDF's first page to an image. However, the PDF is coming straight from the database in a base64 format. I then convert it to a blob. I want to know if it's possible to convert the first page of the PDF to an image within my Python code.

I'm familiar with being able to use filename in the Image object:

Image(filename="test.pdf[0]") as img:

The issue I'm facing is there is not an actual filename, just a blob. This is what I have so far, any suggestions would be appreciated.

x = object['file']
fileBlob = base64.b64decode('x')
with Image(**what do I put here for pdf blob?**) as img:
    more code
like image 654
rachiebytes Avatar asked Oct 31 '22 17:10

rachiebytes


1 Answers

It works for me

all_pages = Image(blob=blob_pdf)        # PDF will have several pages.
single_image = all_pages.sequence[0]    # Just work on first page
with Image(single_image) as i:
    ...
like image 77
Vadym Avatar answered Nov 15 '22 05:11

Vadym