问题
i try to do the following:
- Download a PDF file to memory
- Convert the first page to an image
- Use that image with tweepy
I tried the following code, but run into an error.
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')
Here is the error:
TypeError: Can't convert '_io.BytesIO' object to str implicitly
The generated image should later be used to upload it to twitter by tweepy. I don't need to store it to disk, that's why i try to do all in memory. Anybody who could help me please?
来源:https://stackoverflow.com/questions/50764130/python3-download-pdf-to-memory-and-convert-first-page-to-image