Error on Load PDF into Viewer and PDF not displaying correct

I have an event script for a mouse click that opens the PDF viewer and loads a PDF that is a nvarchar set of bytes in my DB. When I click the button to open the PDFViewer and load the file everything works as expected EXCEPT I also get following error:

[code]Traceback (innermost last):

File “event:mouseClicked”, line 4, in ?

java.lang.ClassCastException: Cannot coerce value ‘[Client]currProject’ into type: class [Ljava.lang.Object;

java.lang.ClassCastException: java.lang.ClassCastException: Cannot coerce value ‘[Client]currProject’ into type: class [Ljava.lang.Object;

Ignition v7.3.3 (b570)
Java: Sun Microsystems Inc. 1.6.0_31
[/code]

My event script is as follows:

[code]system.tag.writeToTag("[Client]fileLoc", event.source.text)
system.nav.openWindow(‘File’)

result = system.db.runPrepQuery(“SELECT SU38, SU38bytes FROM ProjectSummary WHERE SU1 = ?”,"[Client]currProject","[Client]currProject")
if result != None:
window = system.gui.getWindow(‘File’)
window.getRootContainer().getComponent(‘PDFViewer’).setBytes(result[0][1])
window.getRootContainer().getComponent(‘PDFViewer’).text = (result[0][0])

system.nav.centerWindow(‘File’)[/code]

Is there a way to suppress or correct this?

I also noticed that the PDF does not display all the ‘layers’ correctly and I noticed this error in the console, is there a way to correct this color/layer display issue?

java.lang.IllegalArgumentException: Color parameter outside of expected range: Component 1 at java.awt.Color.<init>(Unknown Source) at com.ribs.pdf.DefaultFactories.createColor(DefaultFactories.java:144) at com.ribs.pdf.PDFPageParser.getColor(PDFPageParser.java:1428) at com.ribs.pdf.PDFPageParser.parse(PDFPageParser.java:865) at com.ribs.pdf.PDFPageParser.parse(PDFPageParser.java:542) at com.ribs.pdf.PDFPageParser.parsePage(PDFPageParser.java:56) at com.ribs.pdf.PDFPage.parse(PDFPage.java:482) at com.ribs.pdf.PDFPage.getImage(PDFPage.java:473) at com.reportmill.graphics.RMPDFImageReader.getImage(RMPDFImageReader.java:74) at com.reportmill.graphics.RMImageData.awt(RMImageData.java:418) at com.reportmill.graphics.RMImageFill.awt(RMImageFill.java:602) at com.reportmill.graphics.RMImageFill.paintShape(RMImageFill.java:362) at com.reportmill.shape.RMShapePainter.paintShape(RMShapePainter.java:166) at com.reportmill.shape.RMShapePainter.paintShape_super(RMShapePainter.java:145) at com.reportmill.shape.RMShapePainter.paintShapeDeep(RMShapePainter.java:90) at com.reportmill.shape.RMShapePainter.paintShapeDeep(RMShapePainter.java:98) at com.reportmill.RMViewer.paintComponent(RMViewer.java:554) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JComponent.paintChildren(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JViewport.paint(Unknown Source) at javax.swing.JComponent.paintChildren(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JComponent.paintChildren(Unknown Source) at com.inductiveautomation.vision.api.client.components.model.AbstractVisionPanel.paintChildren(AbstractVisionPanel.java:222) at javax.swing.JComponent.paint(Unknown Source) at com.inductiveautomation.factorypmi.plugins.reporting.components.ReportBase.paint(ReportBase.java:179) at javax.swing.JComponent.paintToOffscreen(Unknown Source) at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source) at javax.swing.RepaintManager$PaintManager.paint(Unknown Source) at javax.swing.RepaintManager.paint(Unknown Source) at javax.swing.JComponent._paintImmediately(Unknown Source) at javax.swing.JComponent.paintImmediately(Unknown Source) at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source) at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source) at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source) at javax.swing.RepaintManager.access$700(Unknown Source) at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$000(Unknown Source) at java.awt.EventQueue$1.run(Unknown Source) at java.awt.EventQueue$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)

It looks like the file was never loading correctly from the DB, just being loaded locally from some old code when it appeared to be working…

I’ll work on that part but has anyone had problems with PDFs not loading correctly in the Viewer?

In regards to the first error, when scripting, you have to use system.tag.read() to get a tag’s value, you can’t simply just refer to its name. Calling system.tag.read(“path/to/tag”).value will return the value of that tag. Changing your runPrepQuery to this will fix your problem:

val = system.tag.read("[Client]currProject") result = system.db.runPrepQuery("SELECT SU38, SU38bytes FROM ProjectSummary WHERE SU1 = ?",[val.value],val.value)

For the second error, try using the ActiveX pdf viewer and see if that fixes your problem. If not, see if it works in Adobe Acrobat itself. A workaround could be to use an event handler script and the function system.net.openURL() and open the file with whatever program your OS associates with that file extension. Not the most elegant solution, but it is functional. Here is more info about openURL():

inductiveautomation.com/support/ … penurl.htm

Haha yes, I made that basic mistake with regards to the system.tag.read() function. Corrected it after that, been looking at this screen too long that day I guess.

Using the Adobe PDF Reader Active X plugin corrected the missing layers issue with the PDF. Thanks for that.

Having another issue with the binary data load to SQL but I’ll gather the error info and post that in another topic. FYI, I’ve been referencing http://www.inductiveautomation.com/forum/viewtopic.php?f=54&t=3755&p=6882&hilit=pdf+from+sql#p6882

Glad to help, we’ll keep an eye out for the other thread.