# Printing Multiple Reports at Once

**URL:** <https://forum.inductiveautomation.com/t/printing-multiple-reports-at-once/18772>\
**Category:** Ignition\
**Created:** [July 9, 2018, 7:57pm UTC](https://forum.inductiveautomation.com/t/printing-multiple-reports-at-once/18772 "2018-07-09T19:57:27Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 9, 2018, 7:57pm UTC](https://forum.inductiveautomation.com/t/printing-multiple-reports-at-once/18772/1 "2018-07-09T19:57:27Z")

</div>

I have a button that will print the current report viewer, but I want to loop through and print all my reports with a single button push. This is what I’ve got currently without any luck. Thanks,

```auto
reports = ['Optimizer', 'PanelSaw', 'Router', 'LoadSheet']

for item in reports:

  system.report.executeAndDistribute(path=item, 
  project='CNCManagement',
  action='print', 
  actionSettings = {'copies':1})

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 9, 2018, 8:02pm UTC](https://forum.inductiveautomation.com/t/printing-multiple-reports-at-once/18772/2 "2018-07-09T20:02:58Z")

</div>

Printing from the report viewer will use the client machine’s printer choices. Printing via executeAndDistribute() will use the gateway’s printer choices. You need to make sure your gateway has a printer configured, and that the gateway service has permission to use it.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 9, 2018, 8:16pm UTC](https://forum.inductiveautomation.com/t/printing-multiple-reports-at-once/18772/3 "2018-07-09T20:16:54Z")

</div>

I don’t know how to do that, is there a reference page you can link me to? thanks

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 9, 2018, 8:25pm UTC](https://forum.inductiveautomation.com/t/printing-multiple-reports-at-once/18772/4 "2018-07-09T20:25:37Z")

</div>

Start either [here](https://askubuntu.com/questions/93637/how-do-i-install-my-printer-with-ubuntu), or if you must, [here](https://tutorials.ubuntu.com/tutorial/tutorial-install-ubuntu-server).

The latter is somewhat disruptive – you’ll want to backup your gateway if you go that route.

😈

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 9, 2018, 9:00pm UTC](https://forum.inductiveautomation.com/t/printing-multiple-reports-at-once/18772/5 "2018-07-09T21:00:08Z")

</div>

I really don’t understand the need for ubuntu?? I have a networked printer setup named ‘P1Engineer’ I added the printer name to the code

```auto

reports = ['Optimizer', 'PanelSaw', 'Router', 'LoadSheet']

for item in reports:

  system.report.executeAndDistribute(path=item, 
  project='CNCManagement',
  action='print', 
  actionSettings = {'primaryPrinterName':'P1Engineer','copies':1})  

```

but the script does nothing, or at least there is no queue generated for the printer. I figured you’d just add the printer in the ignition gateway somewhere.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 9, 2018, 9:05pm UTC](https://forum.inductiveautomation.com/t/printing-multiple-reports-at-once/18772/6 "2018-07-09T21:05:21Z")

</div>

> [@dkhayes117](#):
>
> I really don't understand the need for ubuntu??

That was my attempt at humor, since I avoid Windows like the plague. The point is that is an operating-system level task, not an Ignition task. You have to go to or remote into the gateway and configure the printer there. And then make sure the gateway service can print to it.

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [July 10, 2018, 6:11am UTC](https://forum.inductiveautomation.com/t/printing-multiple-reports-at-once/18772/7 "2018-07-10T06:11:39Z")

</div>

> [@dkhayes117](#):
>
> reports = ['Optimizer', 'PanelSaw', 'Router', 'LoadSheet']
> 
> for item in reports:
> 
> system.report.executeAndDistribute(path=item,  
> project='CNCManagement',  
> action='print',  
> actionSettings = {'primaryPrinterName':'P1Engineer','copies':1})

So, I tested your code, and it works fine. The printer needs to be accessible from wherever you run that script. If the printer is only accessible from the gateway, and you run that code in the designer or client, it wont print. If the name of the printer is spelled wrong, it won't print, or even error.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 10, 2018, 1:16pm UTC](https://forum.inductiveautomation.com/t/printing-multiple-reports-at-once/18772/8 "2018-07-10T13:16:54Z")

</div>

I’m going to put the multiple reports on the back burner for just a bit and skip to printing a report while changing a parameter which is a tag. It says that the item isn’t serializable. I forced the item to be a string with str() and it worked but changed the tag to ‘Row:1 columns’

```auto
data = event.source.parent.getComponent('Dropdown').data
params = system.dataset.toPyDataSet(data)

for item in params:
 
 system.tag.write("CNC_Global/ReportStyle", item)
  

 reportViewer = event.source.parent.getComponent('Report Viewer')
 
 def finished():
    #We're simply printing the report here, but you could place any amount of work 
    #here that you want to execute once the new report has been generated
    reportViewer.print(None, 1)        
 
#We'll use this function to constantly check to see if the report has finished loading
 def waiting():
 
    #While we're waiting....
    while reportViewer.reportLoading:
        #...don't do anything, just keep checking
        pass       
     
    #Once we get to this point, the report has finished loading, so lets call finished()
    #Using invokeLater so we can finish up in the Event Dispatch Thread
    system.util.invokeLater(finished)
 
#Start the waiting process in an asynchronous thread.
 system.util.invokeAsynchronous(waiting)
```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 10, 2018, 1:30pm UTC](https://forum.inductiveautomation.com/t/printing-multiple-reports-at-once/18772/9 "2018-07-10T13:30:40Z")

</div>

For the multiple report printing I tried the code below, and it works but it prints the last report 4 times instead of one of each of the reports. any ideas??

```auto
reports = ['Optimizer', 'PanelSaw', 'Router', 'LoadSheet']

for item in reports:
 
 event.source.parent.getComponent('Report Viewer').reportPath = item

 reportViewer = event.source.parent.getComponent('Report Viewer')
 
 def finished():
    #We're simply printing the report here, but you could place any amount of work 
    #here that you want to execute once the new report has been generated
    reportViewer.print(None, 0)        
 
#We'll use this function to constantly check to see if the report has finished loading
 def waiting():
 
    #While we're waiting....
    while reportViewer.reportLoading:
        #...don't do anything, just keep checking
        pass       
     
    #Once we get to this point, the report has finished loading, so lets call finished()
    #Using invokeLater so we can finish up in the Event Dispatch Thread
    system.util.invokeLater(finished)
 
#Start the waiting process in an asynchronous thread.
 system.util.invokeAsynchronous(waiting)

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 10, 2018, 2:49pm UTC](https://forum.inductiveautomation.com/t/printing-multiple-reports-at-once/18772/10 "2018-07-10T14:49:24Z")

</div>

> [@pturmel](#):
>
> You need to make sure your gateway has a printer configured, and that the gateway service has permission to use it.

I finally figured out what you meant. I felt really stupid once I did haha. I got it to print but it printed a bunch of one line pages of symbols. Any ideas on that?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 10, 2018, 3:02pm UTC](https://forum.inductiveautomation.com/t/printing-multiple-reports-at-once/18772/11 "2018-07-10T15:02:41Z")

</div>

Oops I think its the wrong printer driver

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 10, 2018, 6:05pm UTC](https://forum.inductiveautomation.com/t/printing-multiple-reports-at-once/18772/12 "2018-07-10T18:05:29Z")

</div>

Just for reference in case someone else might try to do this. Below is my code to print out 4 reports at once, while looping the 4th report through several ‘style’ report parameters, while allowing the user to select the printer to print to from a dropdown menu.

```auto
reports = ['Optimizer', 'PanelSaw', 'Router', 'LoadSheet']

for item in reports:
  if item == 'LoadSheet':
   data = event.source.parent.getComponent('StyleDD').data
   styles = system.dataset.toPyDataSet(data) 
   for row in styles:
   	 for value in row:
   	    params = {'Style':value}
   	    system.report.executeAndDistribute(path=item, 
   	    project='CNCManagement',
   	    parameters = params,
   	    action='print', 
   	    actionSettings = {'primaryPrinterName':event.source.parent.getComponent('PrinterSelect').selectedStringValue,
   	    'copies':1})  
   
  else:
   system.report.executeAndDistribute(path=item, 
   project='CNCManagement',
   action='print', 
   actionSettings = {'primaryPrinterName':event.source.parent.getComponent('PrinterSelect').selectedStringValue,
   'copies':1})  

```
