Accessing PDF's from a Database Table in Perspective

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?


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: (notice an HTTP request to History Report 2&fileType=pdf&project=OnlineDemo)

1 Like

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!



@c-w-t Thanks for sharing that. I like the i-Frame works great.
I noticed when downloading from FF vs Chrome the suggested filename differs, Is there a way to suggest a filename when users prompt to download?

@PGriffith maybe this should be moved to a new post? I just realized this is old and solved.