【Stimulsoft Reports Flex教程】代码打印报表

下载Stimulsoft Reports Flex最新版本

此示例显示如何从代码中打印呈现的报表文档。为此,您需要加载呈现的报表文件,例如将其分配给documentString变量。

要打印报表,您只需要调用呈现的报表对象的print()方法。应出现系统打印对话框(或浏览器的打印对话框):

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

如果只需要打印所需的报表页面,则可以将页面范围传递给print()方法。例如,仅打印1,2,3和5个报表页面:

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");
}

如果要显示内置打印对话框,则应将print()方法的第一个参数设置为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);
}

下面的屏幕截图中,您可以看到示例代码的结果。

【Stimulsoft Reports Flex教程】代码打印报表

下载示例

【Stimulsoft Reports Flex教程】代码打印报表