Print Report from Code

This example shows how to print the rendered report document from code. For this you need to load a rendered report file, for example assign it to the documentString variable.

To print report you only need to call the print() method of the rendered report object. The system print dialog (or the print dialog of the browser) should appear:

private function onPrintReportClick(): void
{
// Create new report object
var report: StiReport = new StiReport();
// Load document from XML string
report.loadDocumentFromString(documentString);
// Print report
report.print();
}


If you need to print only desired report pages, you can pass the pages range to the print() method. For example, print only 1, 2, 3 and 5 report pages:

private function onPrintSelectedPagesClick(): void
{
// Create new report object
var report: StiReport = new StiReport();
// Load document from XML string
report.loadDocumentFromString(documentString);
// Print selected pages (for example: '1, 3, 5-12')
report.print(false, "1-3, 5");
}


If you want to show the built-in print dialog, you should set the first parameter of the print() method to true:

private function onShowPrintDialogClick(): void
{
// Create new report object
var report: StiReport = new StiReport();
// Load document from XML string
report.loadDocumentFromString(documentString);
// Show print dialog
report.print(true);
}


In the screenshot below you can see the result of the sample code.

Print Report from Code