Skip to main content

exportToPNG

Description

Exports a Gantt chart into the PNG format

exportToPNG: (export?: any) => void

Parameters

  • export - object - optional, an object with export settings (see the details)

Example

gantt.exportToPNG();

//or
gantt.exportToPNG({
name: "mygantt.png"
});

//or
gantt.exportToPNG({
name: "mygantt.png",
header: "<h1>My company</h1>",
footer: "<h4>Bottom line</h4>",
locale: "en",
start: "01-04-2026",
end: "11-04-2026",
skin: "terrace",
data: { },
server: "https://myapp.com/myexport/gantt",
raw: true,
callback: (res) => {
alert(res.url);
}
});

Details

note

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

note

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 exportToPNG method takes as a parameter an object with a number of properties (all of the properties are optional):

PropertyDescription
name(string) the name of the output file
skin('terrace', 'skyblue', 'meadow', 'broadway') the skin of the output Gantt chart
locale(string) sets the language that will be used in the output Gantt chart
start(string) sets the start date of the data range that will be presented in the output Gantt chart. The date format is defined by the config
end(string) sets the end date of the data range that will be presented in the output Gantt chart. The date format is defined by the config
data(object) sets a custom data source that will be presented in the output Gantt chart
header(string) specifies the header that will be added to the output PDF image. Note, you can use any HTML here
footer(string) specifies the footer that will be added to the output PDF image. Note, you can use any HTML here
server(string) sets the API endpoint for the request. Can be used with the local install of the export service. The default value is https://export.dhtmlx.com/gantt
raw(boolean) defines that all Gantt markup will be exported as it is, with all custom elements. false by default. Read the details
callback(function) If you want to receive an url to download a generated PNG file, the callback property can be used. It receives a JSON object with the url property
additional_settings(object) an object with additional settings. The object can contain the following attributes:
  • width - (number|string) the width of the output page
  • height - (number|string) the height of the output page
  • The width and height parameters will be ignored if slice_archive is specified.
  • slice_archive - (boolean|object) allows saving large chart by pieces and obtaining them in the archive. As an object, the attribute takes the width and height options. If the piece size is not defined (i.e. slice_archive: true), the default sizes are 1000×1000.
  • slice_check - (boolean) adds an HTML page to the archive. The page lets you check that all pieces are exported correctly.

Exporting large Gantt by pieces

The maximal sizes of the exported file are 10000х10000.

You can increase one of the sizes, and decrease another one correspondingly via the width/height attributes of the additional_settings property. But if the product of the values of the width and height is greater than 100000000 (10000х10000), the output PNG image will be cropped off.

There is the ability to export the gantt by pieces and obtain them in the archive by using the slice_archive attribute of the additional_settings property of the method:

gantt.exportToPNG({
server: "https://export.dhtmlx.com/beta/gantt",
additional_settings: {
//width: 2000,
//height: 2000,
slice_archive: { width: 2000, height: 2000 },
slice_check: true,
}
});

Related sample: Export into PNG images

You can either define the sizes of the output PNG images via setting the attribute as an object with the width and height options:

slice_archive: { width: 2000, height: 2000 }

or you can set the attribute to true. In this case, the exported pieces of the gantt will have default sizes: 1000×1000.

slice_archive: true

Time restrictions

note

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.

note

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.

Need help?
Got a question about the documentation? Reach out to our technical support team for help and guidance. For custom component solutions, visit the Services page.