# Read file of bytes and view into PDF Viewer

**URL:** <https://forum.inductiveautomation.com/t/read-file-of-bytes-and-view-into-pdf-viewer/12660>\
**Category:** Ignition\
**Created:** [February 9, 2017, 10:30am UTC](https://forum.inductiveautomation.com/t/read-file-of-bytes-and-view-into-pdf-viewer/12660 "2017-02-09T10:30:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![adriangarridob](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@adriangarridob](https://forum.inductiveautomation.com/u/adriangarridob)\
**Post date:** [February 9, 2017, 10:30am UTC](https://forum.inductiveautomation.com/t/read-file-of-bytes-and-view-into-pdf-viewer/12660/1 "2017-02-09T10:30:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 9, 2017, 12:59pm UTC](https://forum.inductiveautomation.com/t/read-file-of-bytes-and-view-into-pdf-viewer/12660/2 "2017-02-09T12:59:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![adriangarridob](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@adriangarridob](https://forum.inductiveautomation.com/u/adriangarridob)\
**Post date:** [February 10, 2017, 11:21am UTC](https://forum.inductiveautomation.com/t/read-file-of-bytes-and-view-into-pdf-viewer/12660/3 "2017-02-10T11:21:59Z")

</div>

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](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/8f9dc96de9ad5cc2e6d5ba67902f6b27cab0001e.sql) (1.68 MB)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 11, 2017, 12:31am UTC](https://forum.inductiveautomation.com/t/read-file-of-bytes-and-view-into-pdf-viewer/12660/4 "2017-02-11T00:31:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![adriangarridob](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@adriangarridob](https://forum.inductiveautomation.com/u/adriangarridob)\
**Post date:** [February 13, 2017, 8:35am UTC](https://forum.inductiveautomation.com/t/read-file-of-bytes-and-view-into-pdf-viewer/12660/5 "2017-02-13T08:35:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adriangarridob](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@adriangarridob](https://forum.inductiveautomation.com/u/adriangarridob)\
**Post date:** [February 13, 2017, 9:32am UTC](https://forum.inductiveautomation.com/t/read-file-of-bytes-and-view-into-pdf-viewer/12660/6 "2017-02-13T09:32:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 6, 2020, 3:34pm UTC](https://forum.inductiveautomation.com/t/read-file-of-bytes-and-view-into-pdf-viewer/12660/7 "2020-11-06T15:34:18Z")

</div>

A post was split to a new topic: [Fond rendering issue with PDF viewer](https://forum.inductiveautomation.com/t/fond-rendering-issue-with-pdf-viewer/40399)
