我正在尝试将PDF的第一页转换为图像。但是,PDF以base64格式直接来自数据库。然后我把它转换成一个团。我想知道是否有可能在我的Python代码中将PDF的第一页转换为图像。
我熟悉能够在图像对象中使用filename:
Image(filename="test.pdf[0]") as img:
我面临的问题是没有一个实际的文件名,只是一个blob。这是我目前所掌握的,如有任何建议,我将不胜感激。
x = object['file']
fileBlob = base64.b64decode('x')
with Image(**what do I put here for pdf blob?**) as img:
more code
它适合我
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:
...
文档中提到了一些关于blobs的内容。所以应该是:
with Image(blob=fileBlob):
#etc etc
我没有测试,但我认为这是你想要的