How to Export Custom CSS with Balkan OrgChart
When exporting a chart with Balkan OrgChart JS, you might want your custom styles β like fonts, colors, and shapes β to be preserved in the exported PDF. Here's how you can make sure those styles go with it.
Code Example
π§© The Problem
OrgChart allows you to export charts as PDFs, but by default, it may not include custom CSS styles defined in your page. For example, you might have styles for specific tags or a unique font that isn't reflected in the exported file.
π οΈ The Solution: Hook into exportstart
You can include custom CSS during export by listening to the exportstart
event and injecting your styles. Here's the key snippet:
chart.on('exportstart', function (sender, args) {
args.styles += document.getElementById('myStyles').outerHTML;
});
This appends the <style>
block (with ID myStyles
) to the exported document, ensuring all your visual tweaks β like custom node fonts and colors β are included.
βοΈ Full Example
Hereβs a simplified breakdown:
<style id="myStyles">
@import url("https://fonts.googleapis.com/css?family=Gochi+Hand");
.node {
font-family: 'Gochi Hand';
}
.node.HR line {
stroke: #E99113;
}
</style>
chart.on('exportstart', function (sender, args) {
args.styles += document.getElementById('myStyles').outerHTML;
});
π The Result
Now, whether you export using the default PDF menu or a custom button, your org chart will keep the same styling as seen on screen β custom fonts, tag-based colors, and all.
How-To-Export-Styles - Org-Chart-JS