Export Report from Code

This example shows how to export a report to various formats from code. For example, export a report to the PDF format. For this you need to create an export settings object of the StiPdfExportSettings type and export service object of the StiPdfExportService type. The exported file will be saved in a byte array. Finally, to start the export process, you only need to call the exportPdf() method, as parameters you need to pass the rendered report object, byte array buffer and export settings:

private function onExportPDFClick(): void
{
// Create new report object
var report: StiReport = new StiReport();
// Load document from XML string
report.loadDocumentFromString(documentString);
// Create a new PDF export service
var service: StiPdfExportService = new StiPdfExportService();
// Create a new PDF export settings
var settings: StiPdfExportSettings = new StiPdfExportSettings();
// Create a buffer for report exporting
var buffer: ByteArray = new ByteArray();
// Export report to ByteArray
service.exportPdf(report, buffer, settings);
}


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

Export Report from Code