Export Options

The Kendo UI Diagram allows you to export it to PDF, PNG, and SVG formats and to save it in PDF directly in the browser.

Exporting to Available File Formats

To implement the desired export options, use the exportPDF, exportImage, or exportSVG methods respectively.

<div id="vueapp" class="vue-app">
    <div>
        <kendo-button @click="onClickPDF" class="k-primary">PDF Export</kendo-button>
        <kendo-button @click="onClickPNG" class="k-primary">PNG Export</kendo-button>
        <kendo-button @click="onClickSVG" class="k-primary">SVG Export</kendo-button>
    </div>
    <br />
    <kendo-hierarchicaldatasource ref="remoteDataSourceComponent"
                                  :data="diagramData"
                                  :schema-model-children="'items'">
    </kendo-hierarchicaldatasource>

    <kendo-diagram ref="diagram1"
                   :data-source-ref="'remoteDataSourceComponent'"
                   :layout-type="'layered'"
                   :shape-defaults-visual="visualTemplate"
                   :connection-defaults-stroke-color="'#979797'"
                   :connection-defaults-stroke-width="2"
                   @kendowidgetready="kendowidgetready">
    </kendo-diagram>

    <script id="template" type="text/x-kendo-template">
      <div class="shape">
        <span class='k-icon #= icon #' style='font-size: 55px; padding-top: 3px;'></span>
      </div>
    </script>
</div>
Vue.use(DiagramInstaller);
Vue.use(DataSourceInstaller);
Vue.use(ButtonsInstaller);

new Vue({
    el: '#vueapp',
    data: function() {
        return {
            diagramModel: {
                children: 'items'
            },
            diagramData: [{
                name: 'My Documents',
                icon: 'k-i-folder-open',
                colorScheme: '#1696d3',
                items: [{
                    name: 'Kendo UI Project',
                    icon: 'k-i-folder-open',
                    colorScheme: '#ef6944',
                    items: [{
                        name: 'Images',
                        icon: 'k-i-folder',
                        colorScheme: '#ef6944'
                    }]
                }, {
                    name: 'New Web Site',
                    icon: 'k-i-folder-open',
                    colorScheme: '#ee587b',
                    items: [{
                        name: 'Research',
                        icon: 'k-i-folder',
                        colorScheme: '#ee587b'
                    }]
                }, {
                    name: 'Reports',
                    icon: 'k-i-folder-open',
                    colorScheme: '#75be16',
                    items: [{
                        name: 'April',
                        icon: 'k-i-folder',
                        colorScheme: '#75be16'
                    }]
                }]
            }]
        }
    },
    methods: {
        onClickPDF: function (ev) {
            var diagram = this.$refs.diagram1.kendoWidget();
            diagram.exportPDF({ paperSize: "auto", margin: { left: "1cm", top: "1cm", right: "1cm", bottom: "1cm" } }).done(function(data) {
                kendo.saveAs({
                    dataURI: data,
                    fileName: "diagram.pdf",
                    proxyURL: "https://demos.telerik.com/kendo-ui/service/export"
                });
            });
        },
        onClickPNG: function (ev) {
            var diagram = this.$refs.diagram1.kendoWidget();
            diagram.exportImage().done(function(data) {
                kendo.saveAs({
                    dataURI: data,
                    fileName: "diagram.png",
                    proxyURL: "https://demos.telerik.com/kendo-ui/service/export"
                });
            });
        },
        onClickSVG: function (ev) {
            var diagram = this.$refs.diagram1.kendoWidget();
            diagram.exportSVG().done(function(data) {
                kendo.saveAs({
                    dataURI: data,
                    fileName: "diagram.svg",
                    proxyURL: "https://demos.telerik.com/kendo-ui/service/export"
                });
            });
        },
        kendowidgetready: function (widget) {
            kendo.pdf.defineFont({
                "FontAwesome":
                    "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/fonts/fontawesome-webfont.ttf"
              });
            widget.bringIntoView(widget.shapes)
        },
        visualTemplate: function (options) {
            var geom = kendo.geometry;
            var draw = kendo.drawing;

            var contentTemplate = kendo.template($("#template").html());

            var dataviz = kendo.dataviz;
            var g = new dataviz.diagram.Group();
            var dataItem = options.dataItem;

            var renderElement = $("<div />").appendTo("body");
            renderElement.html(contentTemplate(dataItem));

            var output = new kendo.drawing.Group();
            draw.drawDOM(renderElement)
            .then(function(group) {
              output.append(group);

              /* Clean-up */
              renderElement.remove();
            });

            g.append(new dataviz.diagram.Rectangle({
                width: 210,
                height: 60,
                stroke: {
                    width: 0
                },
                fill: dataItem.colorScheme
            }));

            g.append(new dataviz.diagram.TextBlock({
                text: dataItem.name,
                x: 85,
                y: 20,
                fill: "#fff"
            }));

            g.drawingElement.append(output);

            return g;
        }
    }
})

Saving in PDF

To save the Diagram in PDF directly in the browser, use the saveAsPDF method.

<div id="vueapp" class="vue-app">
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.css">
    <div>
        <kendo-button @click="onClick" class="k-primary">Save as PDF</kendo-button>
    </div>
    <br />
    <kendo-hierarchicaldatasource ref="remoteDataSourceComponent"
                                  :data="diagramData"
                                  :schema-model-children="'items'">
    </kendo-hierarchicaldatasource>

    <kendo-diagram ref="diagram1"
                   :data-source-ref="'remoteDataSourceComponent'"
                   :layout-type="'layered'"
                   :shape-defaults-visual="visualTemplate"
                   :connection-defaults-stroke-color="'#979797'"
                   :connection-defaults-stroke-width="2"
                   @kendowidgetready="kendowidgetready">
    </kendo-diagram>

    <script id="template" type="text/x-kendo-template">
      <div class="shape">
        <span class='k-icon #= icon #' style='font-size: 55px; padding-top: 3px;'></span>
      </div>
    </script>
</div>
Vue.use(DiagramInstaller);
Vue.use(DataSourceInstaller);
Vue.use(ButtonsInstaller);

new Vue({
    el: '#vueapp',
    data: function() {
        return {
            diagramModel: {
                children: 'items'
            },
            diagramData: [{
                name: 'My Documents',
                icon: 'k-i-folder-open',
                colorScheme: '#1696d3',
                items: [{
                    name: 'Kendo UI Project',
                    icon: 'k-i-folder-open',
                    colorScheme: '#ef6944',
                    items: [{
                        name: 'logo.png',
                        icon: 'k-i-image',
                        colorScheme: '#ef6944'
                    }]
                }, {
                    name: 'New Web Site',
                    icon: 'k-i-folder-open',
                    colorScheme: '#ee587b',
                    items: [{
                        name: 'Research.pdf',
                        icon: 'k-i-file-pdf',
                        colorScheme: '#ee587b'
                    }]
                }, {
                    name: 'Reports',
                    icon: 'k-i-folder-open',
                    colorScheme: '#75be16',
                    items: [{
                        name: 'April.pdf',
                        icon: 'k-i-file-pdf',
                        colorScheme: '#75be16'
                    }]
                }]
            }]
        }
    },
    methods: {
        onClick: function (ev) {
            var diagram = this.$refs.diagram1.kendoWidget();
            diagram.saveAsPDF();
        },
        kendowidgetready: function (widget) {
            kendo.pdf.defineFont({
              "FontAwesome":
                  "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/fonts/fontawesome-webfont.ttf"
            });
            widget.bringIntoView(widget.shapes)
        },
        visualTemplate: function (options) {
            var geom = kendo.geometry;
            var draw = kendo.drawing;

            var contentTemplate = kendo.template($("#template").html());

            var dataviz = kendo.dataviz;
            var g = new dataviz.diagram.Group();
            var dataItem = options.dataItem;

            var renderElement = $("<div />").appendTo("body");
            renderElement.html(contentTemplate(dataItem));

            var output = new kendo.drawing.Group();
            draw.drawDOM(renderElement)
            .then(function(group) {
              output.append(group);

              /* Clean-up */
              renderElement.remove();
            });

            g.append(new dataviz.diagram.Rectangle({
                width: 210,
                height: 60,
                stroke: {
                    width: 0
                },
                fill: dataItem.colorScheme
            }));

            g.append(new dataviz.diagram.TextBlock({
                text: dataItem.name,
                x: 85,
                y: 20,
                fill: "#fff"
            }));

            g.drawingElement.append(output);

            return g;
        }
    }
})

In this article