Export two pivot instances to one PDF file

Export and print

by Flexmonster Pivot Table

HTML

<link rel="stylesheet" href="https://s3.amazonaws.com/flexmonster/2.3/demo.css">
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

<button onclick="exportPDF()">Export to PDF</button>
<div id="pivot-container-1"></div>
<div id="pivot-container-2"></div>

JavaScript

function exportPDF() {
        pivot1.exportTo("pdf", { destinationType: "plain" }, function(res) {
            var pdf1 = res.data;
            pivot2.exportTo("pdf", { destinationType: "plain" }, function(res) {
                var pdf2 = res.data;
                concatPDF(pdf1, pdf2).save(res.filename);
            });
        });
    }

    function concatPDF(pdf1, pdf2) {
        pdf2.internal.pages.forEach(function(page) {
            pdf1.addPage();
            pdf1.internal.pages[pdf1.internal.pages.length - 1] = page;
        });
        return pdf1;
    }

    var pivot1 = new Flexmonster({
        container: "pivot-container-1",
        componentFolder: "https://cdn.flexmonster.com/",
        toolbar: true,
        width: "100%",
        height: "300px",
        report: {
            dataSource: {
                filename: "https://cdn.flexmonster.com/data/data.json"
            },
            slice: {
                rows: [{
                    uniqueName: "Category"
                }],
                columns: [{
                        uniqueName: "Business Type"
                    },
                    {
                        uniqueName: "[Measures]"
                    }
                ],
                measures: [{
                    uniqueName: "Quantity"
                }],
            }
        }
    });

    var pivot2 = new Flexmonster({
        container: "pivot-container-2",
        componentFolder: "https://cdn.flexmonster.com/",
        toolbar: true,
        width: "100%",
        height: "300px",
        report: {
            dataSource: {
                filename: "https://cdn.flexmonster.com/data/data.json"
            }
        }
    });