简体   繁体   English

使用 pdf url (pdf2image) 将 pdf 转换为图像

[英]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?如何使用 pdf file-url( https://example.com/xyz.pdf ) 获取图像?

Fetch the data using your favourite HTTP library:使用您最喜欢的 HTTP 库获取数据:

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

增加@fqrt 的答案,我们需要在 requests.get 中添加 stream=True

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM