# Using Scripting on a Button to Print a Report

**URL:** <https://forum.inductiveautomation.com/t/using-scripting-on-a-button-to-print-a-report/18586>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [June 22, 2018, 7:17pm UTC](https://forum.inductiveautomation.com/t/using-scripting-on-a-button-to-print-a-report/18586 "2018-06-22T19:17:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![klichtenauer4](https://avatars.discourse-cdn.com/v4/letter/k/d78d45/32.png) [@klichtenauer4](https://forum.inductiveautomation.com/u/klichtenauer4)\
**Post date:** [June 22, 2018, 7:17pm UTC](https://forum.inductiveautomation.com/t/using-scripting-on-a-button-to-print-a-report/18586/1 "2018-06-22T19:17:44Z")

</div>

Hello, I am trying to use a print button to print out a report. I have a Report Viewer on the page with the print button and am trying to print to a computer on the client side. Here is what I have right now:

job = system.print.createPrintJob(event.source.parent)  
job.print()

The problem here, is that this ends up printing the entire page that the Report Viewer is on. It’s also printing the page at about 1in tall by 1/2in wide.

I know part of my problem lies in the “(event.source.parent)” part of the script. This points it to the page itself and not the Report Viewer. Is there a way to narrow the scope to just the Report Viewer? Any help would be greatly appreciated. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Paul.Scott](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul.scott/32/4578_2.png) [@Paul.Scott](https://forum.inductiveautomation.com/u/Paul.Scott)\
**Post date:** [June 22, 2018, 7:54pm UTC](https://forum.inductiveautomation.com/t/using-scripting-on-a-button-to-print-a-report/18586/2 "2018-06-22T19:54:18Z")

</div>

The `event.source.parent` portion is getting the container that the Report Viewer is placed in. If you wanted just the Report Viewer, you would need to get a reference to it: `event.source.parent.getComponent('Report Viewer')`

Alternatively, the [Report Viewer](https://docs.inductiveautomation.com/display/DOC79/Report+Viewer) does have its own built-in scripting functions, including a print function, so you could replace your code with:  
`event.source.parent.getComponent('Report Viewer').print()`

---

<div class="post-metadata">

**Author:** ![klichtenauer4](https://avatars.discourse-cdn.com/v4/letter/k/d78d45/32.png) [@klichtenauer4](https://forum.inductiveautomation.com/u/klichtenauer4)\
**Post date:** [June 25, 2018, 3:41pm UTC](https://forum.inductiveautomation.com/t/using-scripting-on-a-button-to-print-a-report/18586/3 "2018-06-25T15:41:08Z")

</div>

Thank you. That’s exactly what I needed.

---

<div class="post-metadata">

**Author:** ![urvishmehta92](https://avatars.discourse-cdn.com/v4/letter/u/f475e1/32.png) [@urvishmehta92](https://forum.inductiveautomation.com/u/urvishmehta92)\
**Post date:** [December 13, 2021, 1:28pm UTC](https://forum.inductiveautomation.com/t/using-scripting-on-a-button-to-print-a-report/18586/4 "2021-12-13T13:28:56Z")

</div>

Hello Paul,  
I have the similar script on one button.

reportViewer = event.source.parent.getComponent(‘Report Viewer’)  
reportViewer.print()

When I press it, It’s opening dialogue box, is there a way I can predefine printing attributes and it will just print the document from Report viewer without dialoguebox.

I tried, reportViewer.setPrinterName(‘PLC-Office’)  
reportViewer.setShowPrintDialog(0)  
but It’s giving me error AttributeError: ‘com.inductiveautomation.reporting.components.Repor’ object has no attribute ‘setShowPrintDialog’

Let me know how can I do this.

---

<div class="post-metadata">

**Author:** ![Paul.Scott](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul.scott/32/4578_2.png) [@Paul.Scott](https://forum.inductiveautomation.com/u/Paul.Scott)\
**Post date:** [December 13, 2021, 4:58pm UTC](https://forum.inductiveautomation.com/t/using-scripting-on-a-button-to-print-a-report/18586/5 "2021-12-13T16:58:02Z")

</div>

That user manual page I linked to included documentation on the `print` function. The second optional parameter allows you to specify if that print dialog should appear.

```auto
reportViewer.print("PLC-Office", False)

```

---

<div class="post-metadata">

**Author:** ![urvishmehta92](https://avatars.discourse-cdn.com/v4/letter/u/f475e1/32.png) [@urvishmehta92](https://forum.inductiveautomation.com/u/urvishmehta92)\
**Post date:** [December 13, 2021, 5:31pm UTC](https://forum.inductiveautomation.com/t/using-scripting-on-a-button-to-print-a-report/18586/6 "2021-12-13T17:31:25Z")

</div>

Perfect. Thank you so much. It’s working now.
