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’
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.
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
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.