How to open an attachment?

I am trying to open a pdf attachment from a button press. Is there an easy way to do this?

Where is the PDF file located?

You can open a PDF file from the client’s PC by using the following code:

filePath = system.file.openFile("pdf")
fileData = system.file.readFileAsBytes(filePath)
1 Like

I was planning to put the files on a share drive for multiple users to be able to access. This way the PDF can be updated by someone with no programming experience. I could even put the PDF files on the gateway computer if that makes things easier.

Yeah, the easiest way would be to put the files on the Ignition server and run that code from a gateway scoped function. You could then bypass the part about doing the openFile since you already know the path to the PDF file.

From there you can then use the PDF viewer component in the designer to visually show the PDF.

There’s some hoops to jump through when mapping a network drive that can be accessed in gateway scope:

So I have it working with the PDF Viewer tool. I have a single window that opens and the file path is bound to a parameter that is passed with the button pressed. When I press the button I get a message that says

“ICEpdf could not open the specified file at filepath.
The file may be corrupt or not a supported file type.”

I press OK and then the file is opened in the PDF Viewer window anyway. How do I prevent the error message?

Thank you in advance,

This is a known bug that’s on our backlog, but since the file is actually opened it’s fairly low priority. The workaround from the bug ticket seems fairly easy to implement:

Workaround: Remove the binding on the PDF Viewer Component’s File Path property to its window’s root container custom property. Instead, set the PDF Viewer’s filePath property equal to the window root container property in an internalFrameActivated event handler on window2.

Ok I will try this in the morning.

Is there a way to do a similar operation of viewing a PDF but instead a with a word document or text file?

It would be nice if this was fixed. I still see it in 8.0.5.

1 Like

We get the error on 8.1.3 and it locks up the PC requiring a reboot.