Show / Hide Table of Contents

Export

OrgChart Exporting

OrgChart JS support the following export formats:

PDF, PNG, SVG, CSV, XML and JSON

Adding export options

In order to enable an export, you need to add a menu item in menu and/or nodeMenu option:

 
    
    menu: {
        pdf: { text: "Export PDF" },
        png: { text: "Export PNG" },
        svg: { text: "Export SVG" },
        csv: { text: "Export CSV" },
        xml: { text: "Export XML" },
        json: { text: "Export JSON" }
    }
    
 
    
    nodeMenu: {
        pdf: { text: "Export PDF" },
        png: { text: "Export PNG" },
        svg: { text: "Export SVG" }
    }
    

Here is the result:


Custom Export options

Export collapsed children:

By default collapsed children will not be exported, if you want to change that you have to add your own export node menu item

First define the export functions:
 

function pdf(nodeId) {
    chart.exportPDF({filename: "MyFileName.pdf", expandChildren: true, nodeId: nodeId});
}
function png(nodeId) {
    chart.exportPNG({filename: "MyFileName.png", expandChildren: true, nodeId: nodeId});
}
function svg(nodeId) {
    chart.exportSVG({filename: "MyFileName.svg", expandChildren: true, nodeId: nodeId});
}
    
Then use the functions in the menu option of the Org Chart definition:
 

    menu: {
        export_pdf: {
            text: "Export PDF",
            icon: OrgChart.icon.pdf(24, 24, "#7A7A7A"),
            onClick: pdf
        },
        export_png: {
            text: "Export PNG",
            icon: OrgChart.icon.png(24, 24, "#7A7A7A"),
            onClick: png
        },
        export_svg: {
            text: "Export SVG",
            icon: OrgChart.icon.svg(24, 24, "#7A7A7A"),
            onClick: svg
        }
    }
    
or/and in the nodeMenu option:
 

    nodeMenu: {
        export_pdf: {
            text: "Export PDF",
            icon: OrgChart.icon.pdf(24, 24, "#7A7A7A"),
            onClick: pdf
        },
        export_png: {
            text: "Export PNG",
            icon: OrgChart.icon.png(24, 24, "#7A7A7A"),
            onClick: png
        },
        export_svg: {
            text: "Export SVG",
            icon: OrgChart.icon.svg(24, 24, "#7A7A7A"),
            onClick: svg
        }
    }
    

In the demo below the chart is collapsed, the children will be expanded on export


Export to A4 format:

First define the function:
 
    
function pdf() {
    chart.exportPDF({
        format: "A4"
    });
}
    
Then use it in a menu option:
 
    
    menu: {
        export_pdf: {
            text: "Export PDF",
            icon: OrgChart.icon.pdf(24, 24, "#7A7A7A"),
            onClick: pdf
        },
    }
    

Add header and footer:

Define the function:
 
    
function pdf() {
    chart.exportPDF({
        format: "A4",
        header: 'My Header',
        footer: 'My Footer. Page {current-page} of {total-pages}'
    });
}
    
Use it in a menu option:
 
    
    menu: {
        export_pdf: {
            text: "Export PDF",
            icon: OrgChart.icon.pdf(24, 24, "#7A7A7A"),
            onClick: pdf
        },
    }
    

Padding on export:

The padding option sets the padding area on all four sides of the tree. You could Add padding on export and preview.

 
    
function pdf() {
    chart.exportPDF({
        padding: 100
    });
}
    

PDF Preview

 
    
function pdf() {
    OrgChart.pdfPrevUI.show(chart, {
        format: "A4",
        header: 'My Header',
        footer: 'My Footer. Page {current-page} of {total-pages}'
    });
}
    

Use the default Fit to page width option to not cut off the nodes at the page break.


Profile export

The exportPDFProfile and exportPNGProfile methods export the node details form.

In the below example we export a node profile after tree loading:

 
    
// add this method before chart.load()
chart.onInit(() => {
    chart.exportPDFProfile({nodeId: 2})
});


Export server

CSV and SVG are client side exports, PDF and PNG are calling BALKAN OrgChart JS export server.

There may be cases where you don't want to use BALKAN OrgChart JS's export server running at https://balkan.app/export, for instance if you are running a secure website or if you don't want your data to be passed to https://balkan.app. In that cases you have to setup your own export server and to change exportUrl option:

 
    
    exportUrl: "https://MyServer.com/export"
    

MyServer is the domain name of you server. It could be hosted under http or https.

Default export server requirements:
  • To be able to export images using the default export server, they need to be public, i.e. you should be able to browse them in any browser.
  • The defaul export service has a limitation of 10Mb for a PDF file size. To be able to export a very large tree(>100 000 nodes), you will need to install your own export server.

Export arguments

You could use onExportStart and onExportEnd methods to change the export behavior.

 
    
// add before chart.load()
chart.onExportStart(() => {
    console.log("exporting")
});
    

CSV/XML

exportstart args: exportend args:
args.ext
args.filename
args.nodes
args.openInNewTab
args.content
args.ext
args.filename
args.nodes

Here is an example of how you could get only the name and the title fiedls, changing args.nodes:

 

// add before chart.load()
chart.onExportStart((args) => {
    if (args.ext == 'csv' || args.ext == 'xml'){
        var newNodes = [];
        for(var i = 0; i < args.nodes.length; i++){
            newNodes.push({
                name: args.nodes[i].name,
                title: args.nodes[i].title
            })
        }
        args.nodes = newNodes;
    }
});
    

Exporting Styles

You can export styles using the property args.styles

HTML:

 
    
<style id="myStyles">
    @import url("https://fonts.googleapis.com/css?family=Gochi+Hand");
    .node {
        font-family: 'Gochi Hand';
    }
    .node.HR rect {
        fill: #E99113;
    }
</style>
 

JavaScript:

 
    
// add before chart.load()
chart.onExportStart((args) => {
    args.styles += document.getElementById('myStyles').outerHTML;
});
 
Code example:
Here we have a demo on how to export styles in Angular.

Here is a code demo on how to export a background image.

Use return false to avoid exporting:

 
    
// add before chart.load()
chart.onExportStart(() => {
    // add your code here
    return false;
});