V1
V1

Export

ActiveReportsJS Viewer supports following commonly used export formats:

  • PDF
  • Excel (.xlsx)
  • HTML

Using ActiveReportsJS Viewer Export pane

To add the available export formats to the viewer -

  • add references to the export scripts in the <head> section of the html,
    <head>
        <!--export to Excel-->
        <script type="text/javascript" src="scripts/ar-js-xlsx.js"></script> 
        <!--export to PDF-->
        <script type="text/javascript" src="scripts/ar-js-pdf.js"></script>
        <!--export to HTML-->
        <script type="text/javascript" src="scripts/ar-js-html.js"></script>
    </head>
  • add a div element to host the viewer in the <body> section of the html,
    <body>
        <div id="ARJSviewerDiv" style="height: 600px"></div>
    </body>
  • initialize the viewer component in the <script> section of the html.
    <script>
        function load() {
            const viewer = new ActiveReports.Viewer('#ARJSviewerDiv');
            viewer.open('/reports/InvoiceList.rdlx-json');

            viewer.availableExports = [];
        }
    </script>

You can show or hide the export formats in the export panel of the viewer, by using viewer.availableExports property. For example,

  • to show all export types, use viewer.availableExports = [];
  • to hide all export types, use viewer.availableExports = [''];
  • to hide export formats other than PDF, use viewer.availableExports = ['pdf'];

The following example shows the complete implementation.

<html>
<head>
    <title>ActiveReportsJS Viewer: Exporting</title>
    <meta charset="utf-8" />

    <link rel="stylesheet" href="css/ar-js-viewer.css" />
    <script type="text/javascript" src="scripts/ie-polyfills.js"></script>
    <script type="text/javascript" src="scripts/ar-js-core.js"></script>
    <script type="text/javascript" src="scripts/ar-js-viewer.js"></script>

    <!--scripts to export-->
    <script type="text/javascript" src="scripts/ar-js-xlsx.js"></script>
    <script type="text/javascript" src="scripts/ar-js-pdf.js"></script>
    <script type="text/javascript" src="scripts/ar-js-html.js"></script>
</head>
<body onload="load()">
    <div id="ARJSviewerDiv" style="height: 600px"></div>
    <script>
        function load() {
            const viewer = new ActiveReports.Viewer('#ARJSviewerDiv');
            viewer.open('/reports/InvoiceList.rdlx-json');

            viewer.availableExports = [];
        }
    </script>
</body>
</html>

Refer to Preset Export Pane topic for information on setting defaults in the export pane.


Using custom button on ActiveReportsJS Viewer Toolbar

If you want to create your own custom button instead of the default export provided by the viewer, use viewer.export() method to pass the export format and settings on button click event. The following example shows complete implementation to export from the custom buttons added on the viewer's toolbar.

<html>
<head>
    <title>Export from custom buttons added on viewer's toolbar</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="css/ar-js-viewer.css" />
    <link rel="stylesheet" href="https://cdn.materialdesignicons.com/2.8.94/css/materialdesignicons.min.css"/>

    <script type="text/javascript" src="scripts/ie-polyfills.js"></script>
    <script type="text/javascript" src="scripts/ar-js-core.js"></script>
    <script type="text/javascript" src="scripts/ar-js-viewer.js"></script>
    <script type="text/javascript" src="scripts/ar-js-xlsx.js"></script>
    <script type="text/javascript" src="scripts/ar-js-pdf.js"></script>
    <script type="text/javascript" src="scripts/ar-js-html.js"></script>

    <script>
        var viewer;
        var pdfExportButton;
        var xlsxExportButton;
        var htmlExportButton;
    </script>
</head>
<body onload="load()">
    <div id="ARJSviewerDiv" style="height: 600px ;width: 100%"></div>
    <script>
            function load() {
                viewer = new ActiveReports.Viewer('#ARJSviewerDiv');

            //add Excel and HTML export icons as svg
             var svgExcelLogo = atob('PHN2ZyB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iIHhtbG5zOmNjPSJodHRwOi8vY3JlYXRpdmVjb21tb25zLm9yZy9ucyMiIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyIgeG1sbnM6c3ZnPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczpzb2RpcG9kaT0iaHR0cDovL3NvZGlwb2RpLnNvdXJjZWZvcmdlLm5ldC9EVEQvc29kaXBvZGktMC5kdGQiIHhtbG5zOmlua3NjYXBlPSJodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy9uYW1lc3BhY2VzL2lua3NjYXBlIiB3aWR0a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DEsMWg1TDEzLDNMMTMsM3ogTTYsMTQgICAgYy0xLjEsMC0yLDAuOS0yLDJ2N2MwLDEuMSwwLjksMiwyLDJoMjNjMS4xLDAsMi0wLjksMi0ydi03YzAtMS4xLTAuOS0yLTItMkg2TDYsMTR6IE0yOSwyMnYxaC01di03aDF2NkgyOUwyOSwyMnogTTE0LDE3djZoMXYtNiBoMnYtMWgtNXYxSDE0TDE0LDE3eiBNMTAsMTl2LTNoMXY3aC0xdi0zSDd2M0g2di03aDF2M0gxMEwxMCwxOXogTTIwLjUsMTlMMTksMTZoLTAuNUgxOHY3aDF2LTVsMSwyaDAuNUgyMWwxLTJ2NWgxdi03aC0wLjVIMjIgTDIwLjUsMTlMMjAuNSwxOXoiLz48L2c+PC9nPjwvc3ZnPg==');    //pdfExportButton using iconCssClass

        //pdfExportButton using iconCssClass
        pdfExportButton = {
            key: 'pdfExternalExportButton',
            iconCssClass: 'mdi mdi-file',
            text: "PDF Export",
            title: "PDF Export",
            checked: true,
            enabled: true,
            action: function (item) {
                var settings = { title: 'Invoice List', userPassword: 'user_Pwd' };
                var cancelCallback = function () {
                    return false;
                }
                viewer.export('pdf', settings, { cancel: cancelCallback })
                    .then(result => result.download("Exported_PDF"));
            }
        };
        //xlsxExportButton using svg icon
        xlsxExportButton = {
            key: 'xlsxExternalExportButton',
            icon: { type: 'svg', content: svgExcelLogo },
            title: "Excel Export",
            checked: true,
            enabled: true,
            action: function (item) {
                var settings = { creator: 'Jack', password: 'Pwd' };
                var cancelCallback = function () {
                    return false;
                }
                viewer.export('xlsx', settings, { cancel: cancelCallback })
                    .then(result => result.download("Exported_XLSX"));
            }
        };
        //htmlExportButton using svg icon
        htmlExportButton = {
            key: 'htmlExternalExportButton',
            icon: { type: 'svg', content: svgHTMLLogo },
            title: "HTML Export",
            checked: true,
            enabled: true,
            action: function (item) {
                var settings = { autoPrint: 'true' };
                var cancelCallback = function () {
                    return false;
                }
                viewer.export('html', settings, { cancel: cancelCallback })
                    .then(result => result.download("Exported_HTML"));
            }
        };
        var Comic = {
            name: 'Comic Sans MS',
            source: 'fonts/comic.ttf',
        };
        /*Register specified fonts on exporting.
        Makes export correct on machines where fonts are missing.*/
        viewer.registerFont(Comic);

        viewer.toolbar.addItem(pdfExportButton);
        viewer.toolbar.addItem(xlsxExportButton);
        viewer.toolbar.addItem(htmlExportButton);

        viewer.toolbar.updateLayout({
            default: ['pdfExternalExportButton', 'xlsxExternalExportButton', 'htmlExternalExportButton', '$navigation', '$history', '$fullscreen', '$split', '$print', '$refresh', '$galleymode', '$mousemode', '$split', '$continuousmode', '$singlepagemode', '$zoom', '$split'],
            fullscreen: ['$navigation', '$fullscreen', 'print', 'galleymode'],
            mobile: ['$refresh', '$mousetool']
        });
        // open rdlx-json file in viewer
        viewer.open('/reports/InvoiceList.rdlx-json');
            }
    </script>
</body>
</html>

Without using viewer (One-Touch Export)

You can export reports without previewing by specifying the export format through code. You can also specify the export settings specific to each export type. Refer to Set Document Properties topic for more information.

PDF

The following code exports report to PDF format without displaying the report's preview.

function load() {
            var ARJS = GC.ActiveReports.Core;
            var PDF = GC.ActiveReports.PdfExport;

            var onProgressCallback = function (pageCount) {
                console.log(pageCount);
            }

            var settings = {
                info: {
                    title: 'Invoice List',
                    author: 'John K',                    
                }
            }                
            var pageReport = new ARJS.PageReport();
            pageReport.load('/reports/InvoiceList.rdlx-json')
                .then(() => pageReport.run())
                .then(pageDocument => PDF.exportDocument(pageDocument, settings, onProgressCallback))
                .then(result => result.download('InvoiceList'));
        }

Excel

The following code exports report to Excel format without displaying the report's preview.

function load() {
            var ARJS = GC.ActiveReports.Core;
            var PDF = GC.ActiveReports.XlsxExport;

            var onProgressCallback = function (pageCount) {
                console.log(pageCount);
            }

            var settings = {
                info: {
                    creator: 'Jack'
                }
            }
            var pageReport = new ARJS.PageReport();
            pageReport.load('/reports/InvoiceList.rdlx-json')
                .then(() => pageReport.run())
                .then(pageDocument => Excel.exportDocument(pageDocument, settings, onProgressCallback))
                .then(result => result.download('InvoiceList'));
        }

HTML

The following code exports report to HTML format without displaying the report's preview.

function load() {
            var ARJS = GC.ActiveReports.Core;
            var HTML = GC.ActiveReports.HtmlExport;

            var onProgressCallback = function (pageCount) {
                console.log(pageCount);
            }

            var settings = {
                autoPrint: true                
            }

            var pageReport = new ARJS.PageReport();
            pageReport.load('/reports/InvoiceList.rdlx-json')
                .then(() => pageReport.run())
                .then(pageDocument => HTML.exportDocument(pageDocument, settings, onProgressCallback))
                .then(result => result.download('InvoiceList'));

        }