Reputation: 1126
I am trying to convert html
to pdf
.
The conversion works fine if I don't include any images, but if I include images it fails with error code 3 and Description BackendError.
I'm referring the image asset included as static/thumb.jpg in my html
asset.
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
Upvotes: 4
Views: 434
Reputation: 19030
In my case BackendError was generated when I referenced an image that was not provided as an asset.
The curious thing was that when an image was referenced by a CSS, but the CSS rule did not apply it worked OK.
The error started showing up when HTML changed and and the previously unused CSS rule — referencing a missing image asset — got applied to the new/changed HTML element.
So it is OK to reference missing image assets in CSS as long as these CSS rules are not used themselves.
Upvotes: 0
Reputation: 8292
This is probably because items you've mapped as static assets in your app.yaml can't be accessed by your app's code. Try either including the image somewhere within your code, or without mapping the images as static in app.yaml.
It sounds like this was because the img src path in the html asset should match the asset path.
Upvotes: 2