Render Report from Code

This example shows how to render a report template from code. First, you need load a report file, for example assign it to the reportString variable. Then you need to create the StiReport object and load the report from this string variable using the loadReportFromString() method. After these actions done, you can render the report using the render() method:

private function onRenderReportClick(): void
// Create new report object
report = new StiReport();
// Load report from XML string
// Add event listener invoked after report is rendered
report.addEventListener(StiReportEvent.END_RENDER, onRenderComplete);
// Render report

The render process is asynchronous, so if you need to do some actions after report rendering, you can add event listener to the StiReportEvent.END_RENDER event of the report object. For example, save rendered report document to string variable:

private function onRenderComplete(event: StiReportEvent): void
// Remove event listener
report.removeEventListener(StiReportEvent.END_RENDER, onRenderComplete);
// Save rendered document to XML string
var documentString: String = report.saveDocumentToString();

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

Render Report from Code