Search results

Export

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

Export event handling

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

  1. Set the exportProgressChanged in Report Viewer initialization.
  2. Implement the function and replace the following code samples to show a custom message based on the progress stage.
index.html
index.js
    <body style="overflow: hidden; position: static; margin: 0; padding: 0; height: 100%; width: 100%;">
    <div id="viewer" style="position: absolute; height: 100%; width: 100%;"></div>
    <script src="index.js"></script>
    </body>
function onExportProgressChanged(args) {
        if (args.stage === "beginExport") {
            console.log(args.stage);
            args.format =
                $('#viewer').ejWaitingPopup({ showOnInit: true, cssClass: "customStyle", text: "Preparing exporting document.. Please wait..." });
        }
        else if (args.stage === "exportStarted") {
            console.log(args.stage);
            var popupObj1 = $('#viewer').data('ejWaitingPopup');
            popupObj1.hide();
        }
        else if (args.stage === "preparation") {
            console.log(args.stage);
            console.log(args.format);
            console.log(args.preparationStage);
            if (args.format === "PDF" && args.preparationStage === "documentPreparation") {
                console.log(args.totalPages);
                console.log(args.currentPage);
                if (args.totalPages > 1 && args.currentPage > 1) {
                    var progressPercentage = Math.floor((args.currentPage / args.totalPages) * 100);
                    if (progressPercentage > 0) {
                        var popupObj2 = $('#viewer').data('ejWaitingPopup');
                        popupObj2.setModel({ text: "Preparing exporting document.." + progressPercentage + " % completed.. Please wait..." });
                    }
                }
            }
        }

        args.handled = true;
    }

$(function () {
    $("#viewer").ejReportViewer({
                    reportServiceUrl: "https://reports.syncfusion.com/demos/services/api/ReportViewer",
                    reportPath: '~/Resources/docs/sales-order-detail.rdl',
                    exportProgressChanged: onExportProgressChanged
                });
});

You can view the Web API service used in the above code from the Reporting Service git hub location. For more information, see Samples and demos.

Change Excel and Word export format

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

index.html
index.js
    <body style="overflow: hidden; position: static; margin: 0; padding: 0; height: 100%; width: 100%;">
    <div id="viewer" style="position: absolute; height: 100%; width: 100%;"></div>
    <script src="index.js"></script>
    </body>
$(function () {
    $("#viewer").ejReportViewer({
                    reportServiceUrl: "https://reports.syncfusion.com/demos/services/api/ReportViewer",
                    reportPath: '~/Resources/docs/sales-order-detail.rdl',
					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.

index.html
index.js
    <body style="overflow: hidden; position: static; margin: 0; padding: 0; height: 100%; width: 100%;">
    <div id="viewer" style="position: absolute; height: 100%; width: 100%;"></div>
    <script src="index.js"></script>
    </body>
$(function () {
    $("#viewer").ejReportViewer({
                    reportServiceUrl: "https://reports.syncfusion.com/demos/services/api/ReportViewer",
                    reportPath: '~/Resources/docs/sales-order-detail.rdl',
					exportSettings: { exportOptions: ej.ReportViewer.ExportOptions.All & ~ej.ReportViewer.ExportOptions.Html & ~ej.ReportViewer.ExportOptions.Word }
                });
});

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
    • ej.reporting.common.min.js
    • ej.reporting.widgets.min.js
    • ej.chart.min.js
    • ej.lineargauge.min.js
    • ej.circulargauge.min.js
    • ej.map.min.js
    • ej.report-viewer.min.js
  3. You can replace the following codes in Report Viewer Web API controller.

        public void OnInitReportOptions(ReportViewerOptions reportOption)
        {
            var resourcesPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Scripts");
    
            reportOption.ReportModel.ExportResources.Scripts = new List<string>
            {
                resourcesPath + @"\reports\common\ej.reporting.common.min.js",
                resourcesPath + @"\reports\common\ej.reporting.widgets.min.js",
                //Chart component script
                resourcesPath + @"\reports\data-visualization\ej.chart.min.js",
                //Gauge component scripts
                resourcesPath + @"\reports\data-visualization\ej.lineargauge.min.js",
                resourcesPath + @"\reports\data-visualization\ej.circulargauge.min.js",
                //Map component script
                resourcesPath + @"\reports\data-visualization\ej.map.min.js",
            � � //Report Viewer Script
            � � resourcesPath + @"\reports\data-visualization\ej.chart.min.js",
                resourcesPath + @"\reports\ej.report-viewer.min.js"
            };
    
            reportOption.ReportModel.ExportResources.DependentScripts = new List<string>
            {
                resourcesPath + @"\jquery-1.7.1.min.js"
            };
        }

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

PDF export options

The PDFOptions provides properties to manage PDF export behaviors. You have to 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 Syncfusion.Reporting.Writer.PDFOptions()
        {
            EnableComplexScript = true
        };
    }

PDF Conformance

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

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

Add custom PDF fonts

This allows you to have custom fonts in the PDF exported document by adding the font streams to Fonts collection in PDFOptions instance.

  1. Add the font .ttf files into your application Resources 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 Syncfusion.Reporting.Writer.PDFOptions()
        {
            //Load Missing font stream
            Fonts = new Dictionary<string, System.IO.Stream>
            {
                { "Segoe UI", System.IO.File.OpenRead(System.Web.Hosting.HostingEnvironment.MapPath(@"~/Resources/docs/font_symbols.ttf")) }
            }
         };
     }

Any fonts used in the report definition that is not installed or available in the local system, then you must load the font stream. In the above code, loaded font_symbols font stream to export 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 Syncfusion.Reporting.Writer.WordOptions()
    {
        FormatType = Syncfusion.Reporting.Writer.WordFormatType.Docx
    };

Word document advance layout for merged cells

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

    reportOption.ReportModel.WordOptions = new Syncfusion.Reporting.Writer.WordOptions()
    {
        LayoutOption = Syncfusion.Reporting.Writer.WordLayoutOptions.TopLevel,
        ParagraphSpacing = new Syncfusion.Reporting.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 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 a password. The following are the types of protection.

  1. AllowOnlyComments: You can add or modify only the comments in the Word document.
  2. AllowOnlyFormFields: You can modify the form field values in the Word document.
  3. AllowOnlyRevisions: You can accept or reject the revisions in the Word document.
  4. AllowOnlyReading: You can only view the content in the Word document.
  5. NoProtection: You can access or edit the Word document contents as normally.
    reportOption.ReportModel.WordOptions = new Syncfusion.Reporting.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 Syncfusion.Reporting.Writer.ExcelOptions()
    {
        ExcelSaveType = Syncfusion.Reporting.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 as IgnoreCellMerge.

    reportOption.ReportModel.ExcelOptions = new Syncfusion.Reporting.Writer.ExcelOptions()
    {
        LayoutOption = Syncfusion.Reporting.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 Syncfusion.Reporting.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 Syncfusion.Reporting.Writer.PPTOptions()
    {
        FormatType = Syncfusion.Reporting.Writer.PPTSaveType.PowerPoint2013
    };

CSV export options

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

    reportOption.ReportModel.CsvOptions = new Syncfusion.Reporting.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 Syncfusion.Reporting.Writer.HTMLOptions()
    {
        HidePageSeparator = true
    };

Password protect exported document

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

    public void OnInitReportOptions(ReportViewerOptions reportOption)
    {
        //PDF encryption
        reportOption.ReportModel.PDFOptions = new Syncfusion.Reporting.Writer.PDFOptions();
        reportOption.ReportModel.PDFOptions.Security = new Syncfusion.Pdf.Security.PdfSecurity()
        {
            UserPassword = "password"
        };

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

        //Excel encryption
        reportOption.ReportModel.ExcelOptions = new Syncfusion.Reporting.Writer.ExcelOptions()
        {
            PasswordToModify = "password",
            PasswordToOpen = "password"
        };

        //PPT encryption
        reportOption.ReportModel.PPTOptions = new Syncfusion.Reporting.Writer.PPTOptions()
        {
            EncryptionPassword = "password"
        };
    }

Password protection is not supported for HTML export format.