# system.report.executeAndDistribute?

**URL:** <https://forum.inductiveautomation.com/t/system-report-executeanddistribute/27458>\
**Category:** Ignition Early Access\
**Created:** [August 14, 2019, 10:46pm UTC](https://forum.inductiveautomation.com/t/system-report-executeanddistribute/27458 "2019-08-14T22:46:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wking](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wking/32/21823_2.png) [@wking](https://forum.inductiveautomation.com/u/wking)\
**Post date:** [August 14, 2019, 10:46pm UTC](https://forum.inductiveautomation.com/t/system-report-executeanddistribute/27458/1 "2019-08-14T22:46:46Z")

</div>

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”,.

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

```

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

 ![denied](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/7e057c8a9300e66dd1efde7f70775d9348539660.jpeg)

---

<div class="post-metadata">

**Author:** ![wking](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wking/32/21823_2.png) [@wking](https://forum.inductiveautomation.com/u/wking)\
**Post date:** [August 14, 2019, 11:15pm UTC](https://forum.inductiveautomation.com/t/system-report-executeanddistribute/27458/2 "2019-08-14T23:15:16Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [August 15, 2019, 2:21pm UTC](https://forum.inductiveautomation.com/t/system-report-executeanddistribute/27458/3 "2019-08-15T14:21:44Z")

</div>

If you want to control the printing yourself, you’ll need [system.report.executeReport](https://docs.inductiveautomation.com/display/DOC80/system.report.executeReport) and then send the returned bytes to the print job via something like [system.print.createPrintJob](https://docs.inductiveautomation.com/display/DOC80/system.print.createPrintJob)

---

<div class="post-metadata">

**Author:** ![wking](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wking/32/21823_2.png) [@wking](https://forum.inductiveautomation.com/u/wking)\
**Post date:** [August 15, 2019, 3:20pm UTC](https://forum.inductiveautomation.com/t/system-report-executeanddistribute/27458/4 "2019-08-15T15:20:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [August 15, 2019, 4:11pm UTC](https://forum.inductiveautomation.com/t/system-report-executeanddistribute/27458/5 "2019-08-15T16:11:30Z")

</div>

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

Take a look at [this forum post](http://forum.inductiveautomation.com/t/printing-a-bufferedimage/14696/6) for some ideas on how to roll your own.

---

<div class="post-metadata">

**Author:** ![wking](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wking/32/21823_2.png) [@wking](https://forum.inductiveautomation.com/u/wking)\
**Post date:** [August 15, 2019, 9:03pm UTC](https://forum.inductiveautomation.com/t/system-report-executeanddistribute/27458/6 "2019-08-15T21:03:06Z")

</div>

````auto
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.
