Accessing PDF's from a Database Table in Perspective

#1

I know with Perspective, the PDF Viewer will only show PDF’s where there’s a web path because of how a web browser works. What I wanted to see is if there’s a way, and if so, what the best practice is to look at PDF’s, images, etc. that are stored in MSSQL database tables. Currently in Vision, we read in the bytes and use the .loadPDFBytes function. I know that doesn’t exist in Perspective, but is there a way to run a script on the Gateway to create the PDF, put it in a location, and then be able to view it in Perspective? Is this the recommended way or even possible?

Thanks

0 Likes

#2

The “right” way to do this in a web-based way would be to use the webdev module - you can construct a Python endpoint that fetches the bytes from your database and returns them - that’s exactly how the demo project displays an Ignition report: https://demo.ia.io/data/perspective/client/OnlineDemo/feature/reporting/examples (notice an HTTP request to https://demo.ia.io/system/webdev/OnlineDemo/Reports/GetReport?path=Tag History Report 2&fileType=pdf&project=OnlineDemo)

1 Like

#3

Hi, thanks for the content in this thread, it helped me sort out a solution for my needs. Per the recommendation I used the webdev module and created a python http GET resource that fetches the pdf blob data, and returns it like so:

query = ‘some query string’
data = system.db.runScalarPrepQuery(query,[values])
return {‘contentType’:‘application/pdf’, ‘bytes’:data}

However, I didn’t use the PDF Viewer component in my Perspective Popup view. I instead used an i-frame component which then natively handles the PDF content. You can use an expression or script to load the URL of the i-frame at runtime.

Hope that helps someone!

Cheers,
Clint.

1 Like