Read file of bytes and view into PDF Viewer

Hi, I have tried to retrieve a register of bytes (MEDIUMBLOB) from a Data Base and view the result in a PDF viewer component. I have used the following code:
query=“SELECT doc_pdf FROM incidencias WHERE id= ‘%s’” %(id)
result=system.db.runScalarQuery(query,‘DB’)
event.source.parent.getComponent(‘PDF Viewer’).loadPDFBytes(bytes, “name”)

I got this error:

AttributeError: ‘NoneType’ object has no attribute ‘loadPDFBytes’

How can I read and present this data?

Thank you for the support.

One error at a time. That error says that your getComponent() call didn’t find your PDF Viewer. Check the name and nesting carefully. Or use the wizard to insert a property from that component and cut/paste the resulting code.

Thx, you were right.

Although I’m not getting any error don’t manage to see any information in the PDF Viewer either.

Please find enclosed the DataBase backup. The code I’m using is as follows:

[code]id=event.source.parent.parent.getComponent(‘id’).text
query=“SELECT doc_pdf FROM incidencias WHERE id= ‘%s’” %(id)
result=system.db.runScalarQuery(query,‘DB’)

if query!=None:
event.source.parent.parent.getComponent(‘Container 1’).getComponent(‘PDF Viewer’).loadPDFBytes(result, “name”)
event.source.parent.parent.getComponent(‘Container 1’).visible=1

else:
event.source.parent.parent.getComponent(‘Container 1’).visible=0[/code]
aa.sql (1.68 MB)

It looks like the problem is with the BLOB in the database - even writing the data to a file and loading it in an external PDF viewer gets me an empty PDF - but it doesn’t look like it’s an invalid PDF per se, because it’s got valid headers and footers. Maybe try loading a different PDF into the database.

I’ve already tried with another pdf but I always get the same result.

And I tried the same with images and I have got the same result, the image is not visible.

A post was split to a new topic: Fond rendering issue with PDF viewer