system.report.executeAndDistribute?

Hey guys,

Is there a way to use this function to call up the native print dialog GUI in the browser. I want to run the report from a button but the docs say you have to pass “primaryPrinterName”, “backupPrinterName”,.

	system.report.executeAndDistribute(path="Report", project="Master", action="print",)

this gives me the following. So it seems like it’s trying to print?

	file = 'wip.pdf'
	bytesArray = system.report.executeReport(path="Report", project="Master", fileType="pdf")
	system.perspective.download(file, bytesArray)

If you want to control the printing yourself, you’ll need system.report.executeReport and then send the returned bytes to the print job via something like system.print.createPrintJob

system.print.createPrintJob(event.source.parent.getComponent(‘Container’))`

Thanks for your reply. So how would you bring the bytes into this function? The bytes returned arent a “component” right?

Derp, you’re right. Didn’t have my caffeine yet.

Take a look at this forum post for some ideas on how to roll your own.

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.