gpt4 book ai didi

python - 我可以使用 Python 和 Wand 将 PDF blob 转换为图像吗?

转载 作者:太空宇宙 更新时间:2023-11-03 11:48:48 24 4
gpt4 key购买 nike

我正在尝试将 PDF 的第一页转换为图像。但是,PDF 是以 base64 格式直接来自数据库。然后我将其转换为 blob。我想知道是否可以在我的 Python 代码中将 PDF 的第一页转换为图像。

我熟悉能够在 Image 对象中使用文件名:

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:
...

关于python - 我可以使用 Python 和 Wand 将 PDF blob 转换为图像吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33042695/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com