INFO | jvm 1 | 2019/08/15 15:46:18 | com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last):
INFO | jvm 1 | 2019/08/15 15:46:18 | File "<function:runAction>", line 28, in runAction
INFO | jvm 1 | 2019/08/15 15:46:18 | at java.desktop/javax.print.ServiceUI.printDialog(Unknown Source)
INFO | jvm 1 | 2019/08/15 15:46:18 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
INFO | jvm 1 | 2019/08/15 15:46:18 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
INFO | jvm 1 | 2019/08/15 15:46:18 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
INFO | jvm 1 | 2019/08/15 15:46:18 | at java.base/java.lang.reflect.Method.invoke(Unknown Source)
INFO | jvm 1 | 2019/08/15 15:46:18 | java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: services must be non-null and non-empty```
def runAction(self, event):
Method that will run whenever the selected event fires.
Arguments:
self: A reference to the component that is invoking this function.
event: An object that holds information about the selected event type
"""
# Write your script here
# Executes and distributes the report to save a PDF
#settings = {"path":"C:\\Ignition Reports", "fileName":"Report.pdf", "format":"html"}
#system.report.executeAndDistribute(path="Report", project="Master", action="print",)
#bytesArray = system.report.executeReport(path="Report", project="Master", fileType="pdf")
#job = system.print.createPrintJob(bytesArray)
#job.print
from javax.imageio import ImageIO
from java.awt import Robot, Rectangle
from java.io import File, ByteArrayOutputStream
from javax.print import Doc, DocFlavor, DocPrintJob, PrintService, PrintServiceLookup, SimpleDoc, ServiceUI
from javax.print.attribute import HashPrintRequestAttributeSet, HashDocAttributeSet
from javax.print.attribute.standard import Copies, OrientationRequested
DocAttributeSet = HashDocAttributeSet()
printJobAttributeSet = HashPrintRequestAttributeSet()
rintJobAttributeSet = HashPrintRequestAttributeSet()
printJobAttributeSet.add(Copies(1))
printJobAttributeSet.add(OrientationRequested.LANDSCAPE)
file = 'wip.pdf'
bytesArray = system.report.executeReport(path="Report", project="Master", fileType="pdf")
system.perspective.download(file, bytesArray)
doc=SimpleDoc(bytesArray,DocFlavor.BYTE_ARRAY.PDF,DocAttributeSet)
services = PrintServiceLookup.lookupPrintServices( DocFlavor.BYTE_ARRAY.PDF, None )
service = ServiceUI.printDialog(None,100,100,services,PrintServiceLookup.lookupDefaultPrintService(),None, printJobAttributeSet)
job=service.createPrintJob()
job.print(doc,printJobAttributeSet)
I have played around with it. But, I am way out of my depth. Maybe, someone that is more familiar with these libraries could help eventually.
It would be a nice functionality to add. But, I think I remember reading somewhere that a report viewer is coming to perspective. If that were the case I guess you could use the system.print.createPrintJob. At least, they can download the report to their machines with the system.perspective.download. I don’t care how they print it lol. Onward.