exports a Gantt chart into the PDF format

void exportToPDF( [object export] );
exportobjectoptional, an object with export settings (see the details)


  name: "mygantt.pdf"
    header:"<h1>My company</h1>",
    footer:"<h4>Bottom line</h4>",
    data:{ },
    callback: function(res){


This method is defined in the export extension, so you need to activate the export_api plugin. Read the details in the Export to PDF and PNG article.

If you use the Gantt version older than 8.0, you need to include the https://export.dhtmlx.com/gantt/api.js on your page to enable the online export service, e.g.:

<script src="codebase/dhtmlxgantt.js"></script>
<script src="https://export.dhtmlx.com/gantt/api.js"></script>

The exportToPDF method takes as a parameter an object with a number of properties (all of the properties are optional):

Multi-page export

When Gantt is exported, only its leftmost part is exported to the PDF document each time. Thus, to implement multi-page export, it is necessary to export Gantt several times, shifting Gantt to the left each time.

To shift Gantt in the exported file, you need to add the following style rule to #gantt_here in the header parameter:

const width = 1000;
const height = 1000;
const total_width = gantt.$task_bg.scrollWidth + gantt.$grid.scrollWidth;
for (let i = 0; i < total_width; i += width) {
    header:`<style>#gantt_here{left:-${i}px;position: absolute;}</style>`,
    //raw: true,
      width: width,
      height: height,

Related sample:  Export to the file of defined sizes

In case you want to export Gantt to the specific format ('A4', for example), note, that the file format is defined in millimeters but the size in HTML is specified in pixels. Therefore, you need to convert the shift value from millimeters to pixels.

const widthMM = 297;
const width = widthMM / (25.4 inch / 144 PDF PPI);

Related sample:  Export to the file of defined format

Note, if you export the multi-page Gantt but get only one PDF file, it means that the browser blocks the pop-ups because the function opens them simultaneously. In this case, you need to enable the pop-ups and try exporting again.


Time restrictions

The export service has time restrictions.

If the process takes over than 20 seconds, the export will be canceled and the following error will occur:

Error: Timeout trigger 20 seconds

If several people export Gantt at the same time, the process can take more time than usual. But that's fine because the time which is spent for export request from a specific user is counted separately.

If you need to export large charts, you can use a standalone export module. The export module is provided free of charge if you've obtained Gantt under Commercial, Enterprise or Ultimate license, or you can buy the module separately.

See also
Back to top