Search results

Export report

The Report Viewer provides events and properties to control and customize the report exporting functionality.

Export event handling

You can show the progress information, when the exporting process takes long time to complete using the exportProgressChanged event.

  1. Set the exportProgressChanged event in Report Viewer initialization.
  2. Implement the function and replace the following code samples to get the log message based on the progress stage.
<bold-reportviewer id="reportViewer_Control"
    [reportServiceUrl] = "serviceUrl"
    [processingMode] = "Remote"
    [reportServerUrl] = "serverUrl"
    [reportPath] = "reportPath"
    (exportProgressChanged) = "onExportProgressChanged($event)">
</bold-reportviewer>
import { Component, ViewChild } from '@angular/core';
import { BoldReportsAngularModule } from '@boldreports/angular-reporting-components/src/core';

@Component({
    selector: 'ej-app',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    public serviceUrl: string;
    public reportPath: string;
    public serverUrl: string;

    constructor() {
        this.serviceUrl = 'https://demos.boldreports.com/services/api/ReportApi';
        this.reportPath = 'GroupingAgg.rdl';
    }

    onExportProgressChanged(event) {
        if (event.stage === "beginExport") {
            console.log(event.stage);
        }
        else if (event.stage === "exportStarted") {
            console.log(event.stage);
        }
        else if (event.stage === "preparation") {
            console.log(event.stage);
            console.log(event.format);
            console.log(event.preparationStage);
        }
        event.handled = true;
    }
}

Export data visualization items

To export the reports with data visualization components, it is mandatory to configure the web scripts in Report Viewer Web API controller. If the report definition uses chart, gauge and map report items then configure the scripts in Web API as the following steps,

  1. Open the Report Viewer Web API controller.

  2. Configure the below scripts and styles in OnInitReportOptions on Web API controller.

    • jquery-1.10.2.min.js
    • bold.reports.common.min.js
    • bold.reports.widgets.min.js
    • ej.chart.min.js
    • ej2-base.min.js
    • ej2-data.min.js
    • ej2-pdf-export.min.js
    • ej2-svg-base.min.js
    • ej2-lineargauge.min.js
    • ej2-circulargauge.min.js
    • ej2-maps.min.js
    • bold.report-viewer.min.js
  3. You can replace the following codes in Report Viewer Web API controller.

    public void OnInitReportOptions(ReportViewerOptions reportOption)
    {
        reportOption.ReportModel.ExportResources.Scripts = new List<string>
        {
            "https://cdn.boldreports.com/2.3.39/scripts/common/bold.reports.widgets.min.js",
            "https://cdn.boldreports.com/2.3.39/scripts/common/bold.reports.common.min.js",
            //Gauge component scripts
            "https://cdn.boldreports.com/2.3.39/scripts/common/ej2-base.min.js",
            "https://cdn.boldreports.com/2.3.39/scripts/common/ej2-data.min.js",
            "https://cdn.boldreports.com/2.3.39/scripts/common/ej2-pdf-export.min.js",
            "https://cdn.boldreports.com/2.3.39/scripts/common/ej2-svg-base.min.js",
            "https://cdn.boldreports.com/2.3.39/scripts/data-visualization/ej2-lineargauge.min.js",
            "https://cdn.boldreports.com/2.3.39/scripts/data-visualization/ej2-circulargauge.min.js",
            //Map component script
            "https://cdn.boldreports.com/2.3.39/scripts/data-visualization/ej2-maps.min.js",
            //Chart component script
            "https://cdn.boldreports.com/2.3.39/scripts/data-visualization/ej.chart.min.js",
            //Report Viewer Script
            "https://cdn.boldreports.com/2.3.39/scripts/bold.report-viewer.min.js",
        };
    
        reportOption.ReportModel.ExportResources.DependentScripts = new List<string>
        {
            "https://code.jquery.com/jquery-1.10.2.min.js"
        };
    }

    The data visulization components will not export without the above script configurations.

Export data visualization items in azure environment

Report Viewer uses WebBrowser to export the data visualization items to PDF, Word, Excel file formats. The WebBrowser is not supported in azure environment. To overcome this limitation in azure environment, we have provided an option to export the data visualization report items using PhantomJS.

To download PhantomJS application and deploy it on your machine, you should accept it’s license terms on LICENSE and Third-Party document.

  1. Download PhantomJS from here and extract the download file.
  2. Copy the PhantomJS.exe file from the extracted bin folder and paste into wwwroot/PhantomJS folder in your application.
  3. Open the Report Viewer Web API controller.
  4. Set the UsePhantomJS property to true and PhantomJSPath property in OnInitReportOptions method.
    // Method will be called to initialize the report information to load the report with ReportHelper for processing.
    public void OnInitReportOptions(ReportViewerOptions reportOption)
    {
        string basePath = _hostingEnvironment.WebRootPath;
        reportOption.ReportModel.ExportResources.UsePhantomJS = true;
        reportOption.ReportModel.ExportResources.PhantomJSPath = basePath + @"\PhantomJS\";

        reportOption.ReportModel.ExportResources.Scripts = new List<string>
        {
            "https://cdn.boldreports.com/2.3.39/scripts/common/bold.reports.widgets.min.js",
            "https://cdn.boldreports.com/2.3.39/scripts/common/bold.reports.common.min.js",
            //Gauge component scripts
            "https://cdn.boldreports.com/2.3.39/scripts/common/ej2-base.min.js",
            "https://cdn.boldreports.com/2.3.39/scripts/common/ej2-data.min.js",
            "https://cdn.boldreports.com/2.3.39/scripts/common/ej2-pdf-export.min.js",
            "https://cdn.boldreports.com/2.3.39/scripts/common/ej2-svg-base.min.js",
            "https://cdn.boldreports.com/2.3.39/scripts/data-visualization/ej2-lineargauge.min.js",
            "https://cdn.boldreports.com/2.3.39/scripts/data-visualization/ej2-circulargauge.min.js",
            //Map component script
            "https://cdn.boldreports.com/2.3.39/scripts/data-visualization/ej2-maps.min.js",
            //Chart component script
            "https://cdn.boldreports.com/2.3.39/scripts/data-visualization/ej.chart.min.js",
            //Report Viewer Script
            "https://cdn.boldreports.com/2.3.39/scripts/bold.report-viewer.min.js",
        };

        reportOption.ReportModel.ExportResources.DependentScripts = new List<string>
        {
            "https://code.jquery.com/jquery-1.10.2.min.js"
        };
    }

The Scripts and Dependent scripts must be added to export the items. For more details refer to the export data visualization items section.

Change Excel and Word export format

You can change the default file format to any other file format using the excelFormat and wordFormat properties. The following code sample changes the default versions.

<bold-reportviewer id="reportViewer_Control"
    [reportServiceUrl] = "serviceUrl"
    [processingMode] = "Remote"
    [reportServerUrl] = "serverUrl"
    [reportPath] = "reportPath"
    [exportSettings] = "exportSettings">
</bold-reportviewer>
import { Component, ViewChild } from '@angular/core';
import { BoldReportsAngularModule } from '@boldreports/angular-reporting-components/src/core';

@Component({
    selector: 'ej-app',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    public serviceUrl: string;
    public reportPath: string;
    public serverUrl: string;
    public exportSettings: any;

    constructor() {
        this.serviceUrl = 'https://demos.boldreports.com/services/api/ReportApi';
        this.reportPath = 'GroupingAgg.rdl';
        this.exportSettings = {
            excelFormat: ej.ReportViewer.ExcelFormats.Excel2013,
            wordFormat: ej.ReportViewer.WordFormats.Word2013
        }
    }
}

Hide specific export type for report

Show or hide the default export types available in the component using the exportOptions property. The following code hides the HTML export type from the default export options.

<bold-reportviewer id="reportViewer_Control"
    [reportServiceUrl] = "serviceUrl"
    [processingMode] = "Remote"
    [reportServerUrl] = "serverUrl"
    [reportPath] = "reportPath"
    [exportSettings] = "exportSettings">
</bold-reportviewer>
import { Component, ViewChild } from '@angular/core';
import { BoldReportsAngularModule } from '@boldreports/angular-reporting-components/src/core';

@Component({
    selector: 'ej-app',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    public serviceUrl: string;
    public reportPath: string;
    public serverUrl: string;
    public exportSettings: any;

    constructor() {
        this.serviceUrl = 'https://demos.boldreports.com/services/api/ReportApi';
        this.reportPath = 'GroupingAgg.rdl';
        this.exportSettings = {
            exportOptions: ej.ReportViewer.ExportOptions.All & ~ej.ReportViewer.ExportOptions.HTML & ~ej.ReportViewer.ExportOptions.Word
        }
    }
}

PDF export options

The PDFOptions provides properties to manage PDF export behaviors. You should set the properties in the OnInitReportOptions method of the Web API service.

Export with complex scripts

To export reports with the complex scripts, set the ComplexScript property of PDFOptions instance to true.

        public void OnInitReportOptions(ReportViewerOptions reportOption)
        {
            reportOption.ReportModel.PDFOptions = new BoldReports.Writer.PDFOptions()
            {
                EnableComplexScript = true
            };
        }

PDF conformance

You can export the report as a PDF/A-1b document by specifying the PdfConformanceLevel.Pdf_A1B conformance level in the PdfConformanceLevel property.

        public void OnInitReportOptions(ReportViewerOptions reportOption)
        {
            reportOption.ReportModel.PDFOptions = new BoldReports.Writer.PDFOptions()
            {
                PdfConformanceLevel = Syncfusion.Pdf.PdfConformanceLevel.Pdf_A1B
            };
        }

Add custom PDF fonts

You can add custom fonts to the PDF exported document by adding the font streams to Fonts collection in PDFOptions instance.

To add custom fonts to the PDF exported document, follow these steps:

  1. Add the font .ttf files into your application App_Data folder.
  2. In the Solution Explorer, open the properties of the font file and set the property Copy to Output Directory as Copy always.
  3. Initialize the Font collection and add the font stream to it.

The key value provided in the font collection should be same as in the report item font property.

        public void OnInitReportOptions(ReportViewerOptions reportOption)
        {
            reportOption.ReportModel.PDFOptions = new BoldReports.Writer.PDFOptions()
            {
                //Load Missing font stream
                Fonts = new Dictionary<string, System.IO.Stream>
                {
                    { "Segoe UI", System.IO.File.OpenRead(System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/font_symbols.ttf")) }
                }
            };
        }

If any fonts used in the report definition is not installed or available in the local system, then you should load the font stream. In the above code, font_symbols font stream is loaded to export the Sales Order Detail.rdl report as symbols.

Word export options

The WordOptions provides properties to manage Word document export behaviors.

Word document type

You can save the report to the required document version by setting the FormatType property.

            reportOption.ReportModel.WordOptions = new BoldReports.Writer.WordOptions()
            {
                FormatType = BoldReports.Writer.WordFormatType.Docx
            };

Word document advance layout for merged cells

Eliminate the tiny columns, rows, and merged cells and render the word document elements without nested grid layout by setting the LayoutOption to TopLevel. The ParagraphSpacing is the distance value added between two elements in the document.

            reportOption.ReportModel.WordOptions = new BoldReports.Writer.WordOptions()
            {
                LayoutOption = BoldReports.Writer.WordLayoutOptions.TopLevel,
                ParagraphSpacing = new BoldReports.Writer.ParagraphSpacing()
                {
                    Bottom = 0.5f,
                    Top = 0.5f
                }
            };

A paragraph element is inserted between two tables in the exported document to overcome word document auto merging behavior. The table in the word document is not a stand-alone object. If you draw two tables one after another, it will automatically get merged into a single table. To prevent this merging, added an empty paragraph between two tables.

Protecting Word document from editing

You can restrict a Word document from editing either by providing a password or without password. The following are the types of protection:

  • AllowOnlyComments: Adds or modifies only the comments in the Word document.
  • AllowOnlyFormFields: Modifies the form field values in the Word document.
  • AllowOnlyRevisions: Accepts or rejects the revisions in the Word document.
  • AllowOnlyReading: Allows you to view the content only in the Word document.
  • NoProtection: Accesses or edits the Word document contents as normally.
            reportOption.ReportModel.WordOptions = new BoldReports.Writer.WordOptions()
            {
                ProtectionType = Syncfusion.DocIO.ProtectionType.AllowOnlyReading
            };

Excel export options

The ExcelOptions provides properties to manage Excel document export behaviors.

Excel document type

You can save the report to the required excel version by setting the ExcelSaveType property.

            reportOption.ReportModel.ExcelOptions = new BoldReports.Writer.ExcelOptions()
            {
                ExcelSaveType = BoldReports.Writer.ExcelVersion.Excel2013
            };

Excel document advance layout for merged cells

Eliminate the tiny columns, rows, and merged cells to provide clear readability and perform data manipulations by setting the LayoutOption to IgnoreCellMerge.

            reportOption.ReportModel.ExcelOptions = new BoldReports.Writer.ExcelOptions()
            {
                LayoutOption = BoldReports.Writer.ExcelLayoutOptions.IgnoreCellMerge
            };

Protecting Excel document from editing

You can restrict the Excel document from editing either by providing the ExcelSheetProtection or enabling the ReadOnlyRecommended properties.

            reportOption.ReportModel.ExcelOptions = new BoldReports.Writer.ExcelOptions()
            {
                ReadOnlyRecommended = true,
                ExcelSheetProtection = ExcelSheetProtection.DeletingColumns
            };

PowerPoint export options

You can save the report to the required PowerPoint version by setting the FormatType property.

            reportOption.ReportModel.PPTOptions = new BoldReports.Writer.PPTOptions()
            {
                FormatType = BoldReports.Writer.PPTSaveType.PowerPoint2013
            };

CSV export options

The CsvOptions allows you change encoding, delimiters, qualifiers, extension, and line break of a CSV exported document.

            reportOption.ReportModel.CsvOptions = new BoldReports.Writer.CsvOptions()
            {
                Encoding = System.Text.Encoding.Default,
                FieldDelimiter = ",",
                UseFormattedValues = false,
                Qualifier = "#",
                RecordDelimiter = "@",
                SuppressLineBreaks = true,
                FileExtension = ".txt"
            };

HTML export options

You can hide the separator added at the end of each page by setting the HidePageSeparator property to true.

            reportOption.ReportModel.HTMLOptions = new BoldReports.Writer.HTMLOptions()
            {
                HidePageSeparator = true
            };

Password protect exported document

Allows you protect the exported document such as PDF, Microsoft Word, Microsoft Excel, and PowerPoint from unauthorized users by encrypting the document using encryption password. The following code snippet demonstrates how to encrypt the exported document with user defined password.

        public void OnInitReportOptions(ReportViewerOptions reportOption)
        {
            //PDF encryption

            reportOption.ReportModel.PDFOptions = new BoldReports.Writer.PDFOptions();
            reportOption.ReportModel.PDFOptions.Security = new Syncfusion.Pdf.Security.PdfSecurity()
            {
                UserPassword = "password"
            };

            //Word encryption
            reportOption.ReportModel.WordOptions = new BoldReports.Writer.WordOptions()
            {
                EncryptionPassword = "password"
            };

            //Excel encryption

            reportOption.ReportModel.ExcelOptions = new BoldReports.Writer.ExcelOptions()
            {
                PasswordToModify = "password",
                PasswordToOpen = "password"
            };
            //PPT encryption
            reportOption.ReportModel.PPTOptions = new BoldReports.Writer.PPTOptions()
            {
                EncryptionPassword = "password"
            };
        }

Password protection is not supported for HTML export format.