我尝试执行以下操作:
- 将 PDF 文件下载到内存
- 将第一页转换为图像
- 将该图像与 tweepy 一起使用
我尝试了以下代码,但遇到了错误。
from PIL import Image
from pdf2image import convert_from_path
from urllib.request import urlopen
from io import StringIO, BytesIO
url = 'http://somedomain.com/assets/applets/internet.pdf'
scrape = urlopen(url) # for external files
pdfFile = BytesIO(scrape.read())
pdfFile.seek(0)
pages = convert_from_path(pdfFile,last_page=1, dpi=100)
for page in pages:
page.save('/home/out.jpg', 'JPEG')
这是错误:
TypeError: Can't convert '_io.BytesIO' object to str implicitly
生成的图像稍后应用于通过 tweepy 将其上传到 Twitter。我不需要将其存储到磁盘,这就是为什么我尝试在内存中完成所有操作。
有谁可以帮助我吗?
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)