Using Scripting on a Button to Print a Report

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)

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.

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 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()

Thank you. That’s exactly what I needed.

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

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

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’)
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.

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.

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

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