PNG/SVG Export
You can replace PNG with SVG in all examples.
Use the predefined menu or nodeMenu item to add export:
menu={{ png_export: { text: "Export PNG" } }}Export options
chart.exportToPNG({
childLevels: 1,
parentLevels: 1,
expandChildren: true,
fileName: "myChart.PNG",
header: '<text>My SVG Header</text>',
footer: '<text>My SVG Footer. Slide {current-page} of {total-pages}</text>',
min: false,
openInNewTab: true,
margin: [10, 10, 10, 10],
padding: 50
});Not all options can work together.
Add header and footer
The header and footer are SVG definitions.
First define the function:
function png() {
chartRef.current?.exportToPNG({
header: '<text style="font-size:36px;">My Header</text>',
footer: '<text style="font-size:24px;">My Footer. Page {current-page} of {total-pages}</text>',
});
}Then use it in a menu option:
menu={{
export_png: {
text: "Export to PNG with my header and footer",
icon: OrgChartJS.icon.png(24, 24, "#7A7A7A"),
onClick: png
},
}}PNG Export With Header and Footer Example
Export by pages
You can export multiple charts or export a chart by teams using the pages property.
You can use the following options:
chartRef.current?.exportToPNG({
pages: [
{
content: '<svg><text>My Header</text></svg>',
chartInstance: chart,
nodeId: 2,
expandChildren: true,
childLevels: 2,
parentLevels: 1,
min: false,
header: '<text>My Header</text>',
footer: '<text>My Footer. Page {current-page} of {total-pages}</text>'
}
]
});Export a chart by teams
chartRef.current?.exportToPNG({
expandChildren: false,
pages: [
{
nodeId: 2
},
{
nodeId: 3,
childLevels: 1
},
{
nodeId: 4
},
]
});Export multiple charts in one PNG file
chart1Ref.current?.exportToPNG({
pages: [
{ chartInstance: chart1Ref.current || undefined, header: '<text>OrgChart 1</text>' },
{ chartInstance: chart2Ref.current || undefined, header: '<text>OrgChart 2</text>' },
{ chartInstance: chart3Ref.current || undefined, header: '<text>OrgChart 3</text>' },
{ chartInstance: chart4Ref.current || undefined, header: '<text>OrgChart 4</text>' }
]
});Exporting styles
Using the onExportStart and onExportEnd event listeners, you can change the export behavior. You can export styles using the args.styles property.
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:
const exportStyles = document.getElementById("myStyles")?.outerHTML || "";onExportStart={(args) => { args.styles += exportStyles; }}PNG Preview
You can add PNG/SVG Preview as a menu item:
menu={{ png_preview: { text: "PNG Preview" } }}And/or as a nodeMenu option:
nodeMenu={{ png_preview: { text: "PNG Preview" } }}Click on the menu option to open the preview:
Add header and footer to preview
The header and footer are SVG definitions.
Define the function:
function pngPreview() {
chartRef.current?.pngPreviewUI.show({
header: '<text>My Header</text>',
footer: '<text>My Footer. Page {current-page} of {total-pages}</text>'
});
}Use it in a menu option:
menu={{
pngPreview: {
text: "PNG Preview with Header and Footer",
icon: OrgChartJS.icon.png(24, 24, "#7A7A7A"),
onClick: pngPreview
}
}}PNG Preview with Header and Footer
Add pages programmatically
You can add custom pages in preview using the pages property.
Here is how to export a chart by teams:
function pngPreview() {
chartRef.current?.pngPreviewUI.show({
pages: [
{
nodeId: 2
},
{
nodeId: 3,
childLevels: 1
},
{
nodeId: 4
},
]
});
}PNG Preview add pages Programmatically
Custom content pages
You can add a page with custom content:
function pngExportPreview() {
chartRef.current?.pngPreviewUI.show({
pages: [
{
content: '<svg>[Your SVG definition here]</svg>'
// or
// content: '[Your HTML definition here]'
},
{
nodeId: 2
}
]
});
}Here is how to add a page with a logo:
PNG Preview add custom content
Preview Buttons Configuration
You can hide or show the following buttons:
chartRef.current?.pngPreviewUI.buttons.addNewPage = true;
chartRef.current?.pngPreviewUI.buttons.childLevels = true;
chartRef.current?.pngPreviewUI.buttons.parentLevels = true;
chartRef.current?.pngPreviewUI.buttons.removePage = true;Here is an example:
PNG Preview buttons configuration
Localization
Here is what you can localize in PNG/SVG Preview:
chartRef.current?.pngPreviewUI.locExport = 'Export';
chartRef.current?.pngPreviewUI.locCancel = 'Close';
chartRef.current?.pngPreviewUI.locParentLevels = 'parent levels';
chartRef.current?.pngPreviewUI.locChildLevels = 'child levels';
chartRef.current?.pngPreviewUI.locClickToAdd = 'Click on a node to display it here';
chartRef.current?.pngPreviewUI.locAddNew = 'Add new PNG';
chartRef.current?.pngPreviewUI.locRemove = 'Remove PNG';Here is an example:
Images
Sometimes you may need to convert images to base64 before exporting. Use this constant:
OrgChart.CONVERT_IMAGES_TO_BASE64_BEFORE_EXPORT = true;Server JS
There may be cases where you do not want to use the BALKAN server for export. For example, if you run a secure website or do not want your data to be passed to https://balkan.app.
In that case you need to set up your own Server JS.