我正在尝试转换html
为pdf
.
如果我不包含任何图像,则转换工作正常,但如果我包含图像,则会失败并出现错误代码3和 Description BackendError。
我指的是在我的资产中包含为static/thumb.jpghtml
的图像资产。
def prepare_bar_attachment(bars):
asset = conversion.Asset('text/html',
render_template('bar/print.html',
bars=bars),
'print.html')
thumbnail = None
if bar.thumbnailurl:
img_response = urlfetch.fetch(bar.thumbnailurl)
if img_response.status_code == 200:
thumbnail = conversion.Asset('image/jpeg', img_response.content,
'thumb.jpg')
conv = conversion.Conversion(asset, 'application/pdf')
if thumbnail:
conv.add_asset(thumbnail)
result = conversion.convert(conv)
if result.assets:
attachment = [('Bars.pdf', result.assets[0].data)]
else:
attachment = []
app.logger.error('Error Code: %s\nDescription\%s'%\
(result.error_code, result.error_text))
return attachment