Printing report with a button

Hello All;

As a new user to Ignition, I am still trying to wrap my head around things. I am trying to print a report with the use of a button on the screen. I found that a right click over the report will allow you to print the report, I want to duplicate that function but with a button.

Thanks, Chris

Right just put the following script in the actionPerformed event of the button:report = event.source.parent.getComponent("Report Viewer") report.print()Of course replace the “Report Viewer” with the name of your report. Note: You may also have to change the path depending on where your report is compared to the button.

Thanks Travis,

What if I want to do it with the script module similar to your demo of a screen print?

Chris

You can take a look at the system.print scripting functions:

http://www.inductiveautomation.com/support/usermanuals/ignition/system_print_createimage.htm

Here is an example that will print the root container of the window:rc = system.gui.getParentWindow(event).getRootContainer() job = system.print.createPrintJob(rc) job.setMargins(0.5) job.showPageFormat = 0 job.orientation = orientation job.print()

1 Like

[quote=“Travis.Cox”]Right just put the following script in the actionPerformed event of the button:report = event.source.parent.getComponent("Report Viewer") report.print()Of course replace the “Report Viewer” with the name of your report. Note: You may also have to change the path depending on where your report is compared to the button.[/quote]

Are there also methods for the “Save as PDF/ HTML/PNG”? If so, how do you automate so no human intervention is needed, like to launch reports from a timer script?

To save a report as a PDF with no human intervention, you’d do something like this:

report = event.source.parent.getComponent("Report") bytes = report.getBytesPDF() filename = "C:\\reports\\myreport.pdf" system.file.writeFile(filename, bytes)

1 Like

A little off topic here…

How can I see all the functions associated to a report, like the .print() and .getPDFBytes I think is another one

I want to know if there’s an .open one or something like that

The simplest way is to check the Ignition User Manual: inductiveautomation.com/support … viewer.htm

You could also run code like this from a button, but this finds all the methods and properties:

report = event.source.parent.getComponent("Report Viewer")
print dir(report)

The result will be printed to the Output Console.

Just a little note on what nmudge suggested - not all (in fact, just a small fraction) of what dir() will return is readily usable or useful, and there will be no accompanying documentation.

You may want to search the User Manual by key word instead. There is a whole section on Reporting (the first page is here: https://www.inductiveautomation.com/support/usermanuals/ignition/index.html?reporting_introduction_overview.htm); there is also Appendix C for Scripting functions (check out system.print section)

I copied and gave my report name but i am getting error out as follows in console

File “event:actionPerformed”, line 2, in
TypeError: print(): expected 1 args; got 0

My requirement is to print the report by clicking the button componet, I have used report module to design the report. I am doing scripting to perform this action in actionPerformed event handlers.

Use system.report.executeAndDistribute()

https://docs.inductiveautomation.com/display/DOC79/system.report.executeAndDistribute