Export Multiple Elements from the Page at Once

Thread is closed for posting
1 posts, 0 answers
  1. D41B02FE-0EF9-48A6-9B2C-E910424294F5
    D41B02FE-0EF9-48A6-9B2C-E910424294F5 avatar
    23 posts
    Member since:
    Jul 2012

    Posted 10 Oct 2018 Link to this post

    When exporting parts of the page to PDF through RadClientExportManager, you can pass a single selector. In some cases you may want to export several elements at once. These multiple elements may not even be adjacent or in the same container. You can export them by using the Kendo Drawing APIKendo Drawing Group and the jQuery when() method to utilize the deferreds that the drawDOM() method from the Kendo Drawing API provides.

    Here is the gist, and a full example with comments and explanations is attached below (based on the Page for client-side export code library example):

    function exportMultipleElements() {
        var exportSettings = {
            forcePageBreak: ".pageBreak",
            paperSize: "A3",
            landscape: true
        };
     
        var draw = kendo.drawing;
        var $ = $telerik.$;
        //use a few deferreds at once https://api.jquery.com/jquery.when/
        $.when(
            draw.drawDOM($("#first"), exportSettings),
            draw.drawDOM($("#second"), exportSettings),
            draw.drawDOM($("#third"), exportSettings),
            draw.drawDOM($("#fourth"), exportSettings)
        ).then(function (group1, group2, group3, group4) {//the number of arguments matches the number of deferreds
     
            var group = new kendo.drawing.Group({
                pdf: {
                    multiPage: true
                }
            });
     
            //append the first three pages with the more static content, including the chart
            group.append(group1, group2, group3);
            //append the pages from the grid in the fourth element, see the rest of the functions in the full example to see how the page break selector is appended in the DOM
            group.append.apply(group, group4.children);
     
            return draw.exportPDF(group, exportSettings);
        }).done(function (data) {
            kendo.saveAs({
                dataURI: data,
                fileName: "multi-element-export.pdf"
            });
        });
    }

Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.