4

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
Alex
  • 2,405
  • 4
  • 23
  • 36
Insidi0us
  • 1,088
  • 9
  • 17
  • Can you post corrected code? I don't see what name to correct. – Janusz Skonieczny May 02 '12 at 15:15
  • From the documentation the name of the asset should match the src attribute of the img tag. You can see a sample code here http://stackoverflow.com/questions/10759324/incomplete-google-app-engine-documentation-on-conversion-api/ – Sebastian Kreft Jun 13 '12 at 23:43

2 Answers2

2

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.

Robert Kluin
  • 8,282
  • 25
  • 21
  • Naming the image asset as bar.thumbnail in the above code fixed the problem Also no need to refer the image as static/thumb.jpg or anything special in my html – Insidi0us Jan 20 '12 at 18:23
  • This is a backend error, it has nothing to to with static file access from app code. Assets are all provided in binary form, and then accessed by a Conversion API backend, there the error originates. – Janusz Skonieczny May 03 '12 at 10:53
0

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.

Janusz Skonieczny
  • 17,642
  • 11
  • 55
  • 63
  • You have a different problem. I suggest you post a new questions with your specific details. – Robert Kluin Jun 06 '12 at 06:24
  • It's a similar one — missing asset reference — but it transpired only when a CSS rule (with the missing asset reference) got applied. It was tricky because the error happened in rare cases only. I hope this explanation will help somebody having problems with `Google App Engine Conversion API failing with BackendError` ;) – Janusz Skonieczny Jun 06 '12 at 09:06