2014-01-31 18 views
2

我想生成从Google应用引擎数据库检索图像的pdf。如何使用Platypus将Google应用引擎动态图像对象添加到ReportLab pdf文档中:“ImageReader”对象没有属性“getKeepWithNext”

#Example. This works perfectly fine in the resulting doc 
story.append(Image('http://www.python.org/community/logos/python-logo.png')) 

#Im omitting the details heres, but photo object is correctly created 
photo = ImageReader() 

story.append(photo) 
#Gives me the error: 
#AttributeError: 'ImageReader' object has no attribute 'getKeepWithNext' 

#I thought it might had to cast to an Image object, so i tried: 
story.append(Image(photo)) 
#It gives me the error: 
#AttributeError: 'ImageReader' object has no attribute 'rfind' 

#The error points out to the line where I try to build the doc with the story 
doc = SimpleDocTemplate(stream, pagesize=portrait(A4), etc.) 
doc.build(story) 

我看到了一些解决方案,涉及从画布中添加图像。尽管非常不方便的原因,我宁愿添加添加元素到故事然后创建文档,但我尝试了它。它仍然无法正常工作。

有没有人做到这一点?我的意思是,动态与谷歌应用程序引擎图像和reportlab和platypus。

在此先感谢!

+0

如果你在你的appengine应用程序中有一个可以处理图像的处理程序,那么你可以使用与上面例子完全相同的方法。 ALternatley从blob或blobstore实体创建Image()。 ImageReader __init__接受文件名或URL或StringIO或PIL Image实例作为其实例。 –

回答

0

谢谢@Tim。为了记录,解决方案是将base_url和变量url放在Image()中。防爆。图像(base_url + object_image_url)。它只需要绝对网址。