Skip to content

Exporting to A4 PDF ​

OrgChart JS is a powerful library for visualizing organizational structures, and one of its key features is the ability to export charts to a PDF in A4 format. This feature is useful for printing, sharing, or archiving organizational charts in a standardized format.

How to Export an OrgChart JS Diagram to A4 PDF ​

Follow these simple steps to generate an A4 PDF from your OrgChart JS diagram.

1. Initialize OrgChart JS ​

First, set up your OrgChart JS instance with the desired structure and an export menu option:

javascript
let chart = new OrgChart(document.getElementById("tree"), {
  nodeBinding: {
    field_0: "name",
    field_1: "title"
  },
  menu: {
    export_pdf: {
        text: "Export PDF - A4",
        icon: OrgChart.icon.pdf(24, 24, "#7A7A7A"),
        onClick: pdf
    },
  },
  nodes: [
    { id: 1, name: "CEO", title: "Company Leader" },
    { id: 2, pid: 1, name: "Manager", title: "Department Head" },
    { id: 3, pid: 1, name: "Developer", title: "Software Engineer" }
  ]
});

2. Export to A4 PDF ​

OrgChart JS provides a built-in exportPDF function to generate a PDF:

javascript
function pdf() {
    chart.exportToPDF({
        format: "A4"
    });
}

Customization Options ​

You can customize the exported PDF using additional parameters:

  • Format: Choose between A4, Letter, or other sizes.
  • Padding and Margin: Adjust spacing for better layout.
  • File Name: Specify a custom file name for the exported PDF.
javascript
chart.exportToPDF({
    format: "A4",
    fileName: "OrgChart.pdf",
    padding: 20,
    margin: [15, 10, 10, 10]
});

Conclusion ​

Exporting an organizational chart to an A4 PDF using OrgChart JS is quick and straightforward. This feature ensures that your org chart is easily shareable and print-ready without layout issues.

Try it in your own project to streamline organizational documentation and sharing.