python-2.7 - Reportlab 上的 Appengine 图像 pdf
问题描述
Python 2.7、谷歌应用引擎、ndb.Model
我将 .jpg 图像存储为
signblobkey = ndb.BlobKeyProperty(verbose_name='Signature')
这些完美地存储和显示在 html 页面中。但是,我不知道如何使用reportlab 在.pdf 中“打印”这些内容。
我目前的代码是:
blobattach = ''
blobname = ''
blobmime = 'None'
if self.filetext.signblobkey != None:
blob_info = blobstore.BlobInfo.get(self.filetext.signblobkey)
blobmime = blob_info.content_type[:5]
blobname = blob_info.filename
if blobmime == 'image':
blobattach = get_serving_url(self.filetext.signblobkey)
canvas.ImageReader(StringIO.StringIO(self.filetext.signblobkey))
self.p.drawImage(image=blobattach,
x=self.colleft,
y=c_lineprint - (4 * self.lineheight),
width=self.colright - self.colleft,
height=4 * self.lineheight,
mask=None,
preserveAspectRatio=True,
anchor='nw')
我显然在这里遗漏了一些东西,我似乎没有访问实际图像。对我有什么线索吗?
谢谢,大卫
解决方案
感谢您的上述回答,这使我朝着正确的方向前进。以防万一其他人需要帮助,我终于...
from reportlab.lib.utils import ImageReader
# note self.filetext is a ndb.Model with .signblobkey pointing to my signature
self.signature = None
if self.filetext.signblobkey != None:
blob_info = blobstore.BlobInfo.get(self.filetext.signblobkey)
blobmime = blob_info.content_type[:5]
blobname = blob_info.filename
if blobmime == 'image':
blobattach = get_serving_url(self.filetext.signblobkey)
self.signature = ImageReader(blobattach)
# in the printing routine (I will print a few thousand pages, each with a signature
if self.signature:
self.p.drawImage(image=self.signature,
x=self.colleft,
y=c_lineprint - (4 * self.lineheight),
width=self.colright - self.colleft,
height=4 * self.lineheight,
mask=None,
preserveAspectRatio=True,
anchor='nw')
推荐阅读
- python - Jupyter Notebook 无法识别“导入火炬”
- c++ - 使用数组数组调用 C++ 函数
- apache-spark - 基于类型安全配置文件的气流计划激发作业
- image - 如何格式化docker API?
- php - 您如何限制用于匹配正则表达式的文本
- reactjs - Kendo DataSource 从使用 Axios 获取数据的 Async/await 方法中读取
- c - 有人可以帮我解决用 C 语言对数据结构进行排序的问题吗
- python - Python向数据框显示HTML箭头
- json - 通过角度 6 中的 json 文件访问对象数组中的特定对象
- scala - 使用整数键对 scala hashmap 进行排序不起作用