How to Load a PDF to Viewer on Vision Window Open?

I’m having an issue getting a PDF to load from a database into a PDF View component in a Vision popup on the opening of the window.

I’m passing a database ID to a custom property on the window called BOLGUID.

The following script works in a button on the popup, so I know the database connection and the loading of the PDF is working conceptually.

#Pull data based on BOL GUID from Popup
data = system.db.runNamedQuery("BOLData", {"BOLGUID":event.source.parent.BOLGUID})

#Paint PDF View with BOL
reportBytes = data.getValueAt(0, "PDFStore")
event.source.parent.getComponent('PDF Viewer').loadPDFBytes(reportBytes, "BOL Report")

However, I’ve tried the following script in the internalFrameActivated event on the popup window and it does not load a PDF properly when I open the window

data = system.db.runNamedQuery("BOLData", {"BOLGUID":event.source.rootContainer.BOLGUID})

bytes = data.getValueAt(0, "PDFStore")

system.gui.getParentWindow(event).getComponentForPath('Root Container.PDF Viewer').loadPDFBytes(bytes, "BOL Report")

Any suggestions on where to look?

Whats the Cache Policy of the window? Try setting it to Never. When I have things running at startup that aren’t behaving as I expect that’s one of the first things I try.

Thanks for the tip, gave that a try. Sadly, no difference in response.

What happens if you print bytes right before you try to loadPDFBytes? Do you see data?

I ended up doing some more digging. It appears the script for loading on popup open works fine when in the actual project client, but does not work when I’m in preview mode in the designer.

Is that expected behavior?

Did you have preview mode before you opened the window or was it closed? What happens if close all your windows in designer, put on preview mode, and then open the main window that lets you open this popup and go through it as you would via a client - does it work then?

It still doesn’t seem to work in that instance, but at this point, the code is working, so I can work around knowing that this appears to be a bug or issue with the preview mode

Yea. Ultimately you are always best off testing in a live client.

1 Like