Skip to content

Commit 6ac0003

Browse files
Merge pull request #28 from mlakatkou/GS-3191
[dev] update Export to PDF and PNG article
2 parents 8317102 + c52ec12 commit 6ac0003

1 file changed

Lines changed: 40 additions & 38 deletions

File tree

docs/guides/export.md

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sidebar_label: "Export to PDF and PNG"
55

66
# Export to PDF and PNG
77

8-
dhtmlxGantt provides an online export service that will allow you to export the Gantt chart into the [PDF](guides/export.md#export-to-pdf) or
8+
dhtmlxGantt provides an online export service that allows you to export the Gantt chart into the [PDF](guides/export.md#export-to-pdf) or
99
[PNG](guides/export.md#export-to-png) format.
1010

1111
:::note
@@ -26,7 +26,7 @@ The export service has time and request size restrictions.
2626

2727
### Time limits
2828

29-
If the process takes over than 20 seconds, the export will be canceled and the following error will occur:
29+
If the process takes more than 20 seconds, the export will be canceled and the following error will occur:
3030

3131
~~~html
3232
Error: Timeout trigger 20 seconds
@@ -74,7 +74,7 @@ If you use the Gantt version older than 8.0, you need to include the `https://ex
7474
~~~
7575
:::
7676

77-
- Call the [exportToPDF ](guides/export.md#parameters-of-the-export-methods) method to export the Gantt chart:
77+
- Call the [exportToPDF](api/method/exporttopdf.md) method to export the Gantt chart:
7878

7979
~~~html
8080
<input value="Export to PDF" type="button" onclick='gantt.exportToPDF()'>
@@ -110,7 +110,7 @@ If you use the Gantt version older than 8.0, you need to include the `https://ex
110110
~~~
111111
:::
112112

113-
- Call the [Export to PDF and PNG](guides/export.md#parameters-of-the-export-methods) method to export the Gantt chart:
113+
- Call the [exportToPNG](api/method/exporttopng.md) method to export the Gantt chart:
114114

115115
~~~html
116116
<input value="Export to PNG" type="button" onclick='gantt.exportToPNG()'>
@@ -196,7 +196,7 @@ gantt.exportToPDF({
196196
start: "01-04-2026",
197197
end: "11-04-2026",
198198
skin: "terrace",
199-
data: { },
199+
data: {},
200200
server: "https://myapp.com/myexport/gantt",
201201
raw: true,
202202
callback: (res) => {
@@ -212,7 +212,7 @@ gantt.exportToPNG({
212212
start: "01-04-2026",
213213
end: "11-04-2026",
214214
skin: "terrace",
215-
data: { },
215+
data: {},
216216
server: "https://myapp.com/myexport/gantt",
217217
raw: true,
218218
callback: (res) => {
@@ -240,7 +240,7 @@ To set a custom language for the output file, use the **locale** property in the
240240
~~~js
241241
gantt.exportToPDF({
242242
name: "mygantt.pdf",
243-
locale: "de"
243+
locale: "de"
244244
});
245245
~~~
246246

@@ -277,13 +277,13 @@ To export the Gantt chart with a custom data set (i.e. not with the data present
277277

278278
~~~js {2}
279279
gantt.exportToPDF({
280-
data:{
281-
data:[
280+
data: {
281+
tasks: [
282282
{ id: 1, text: "Project #1", start_date: "01-04-2026", duration: 18 },
283283
{ id: 2, text: "Task #1", start_date: "02-04-2026", duration: 8, parent: 1 },
284284
{ id: 3, text: "Task #2", start_date: "11-04-2026", duration: 8, parent: 1 }
285285
],
286-
links:[
286+
links: [
287287
{ id: 1, source: 1, target: 2, type: "1" },
288288
{ id: 2, source: 2, target: 3, type: "0" },
289289
{ id: 3, source: 3, target: 4, type: "0" },
@@ -338,18 +338,18 @@ element with `class="totalPages"` in the **header**/**footer** properties:
338338

339339
~~~js
340340
gantt.exportToPDF({
341-
additional_settings: {
342-
format: "A4",
343-
// correct margins are obligatory to render headers/footers
344-
margins: {
345-
top: 10,
346-
bottom: 10,
347-
left: 0.1,
348-
right: 1
349-
},
350-
header: "Each page header",
351-
footer: 'Page: <span class="pageNumber"></span>/<span class="totalPages"></span>',
352-
},
341+
additional_settings: {
342+
format: "A4",
343+
// correct margins are obligatory to render headers/footers
344+
margins: {
345+
top: 10,
346+
bottom: 10,
347+
left: 0.1,
348+
right: 1
349+
},
350+
header: "Each page header",
351+
footer: 'Page: <span class="pageNumber"></span>/<span class="totalPages"></span>'
352+
}
353353
});
354354
~~~
355355

@@ -377,9 +377,9 @@ gantt.exportToPDF({
377377
});
378378
~~~
379379

380-
If some of the margin settings isn't specified, it will be ignored.
380+
If some of the margin settings isn't specified, it will be ignored.
381381

382-
The values are set in millimeters by default, but you can specify the values of margins in inches by setting the <b>unit: "inch"</b> property:
382+
The values are set in millimeters by default, but you can specify the values of margins in inches by setting the <b>unit: "inch"</b> property:
383383

384384
~~~js {8}
385385
gantt.exportToPDF({
@@ -404,7 +404,7 @@ To apply a custom style for the gantt, provide the stylesheet with your custom C
404404
~~~js
405405
gantt.exportToPDF({
406406
name: "calendar.pdf",
407-
header: '<link rel="stylesheet" href="http://mysite.com/custom.css">'
407+
header: '<link rel="stylesheet" href="http://mysite.com/custom.css">'
408408
});
409409
~~~
410410

@@ -413,7 +413,7 @@ gantt.exportToPDF({
413413
~~~js
414414
gantt.exportToPDF({
415415
name: "calendar.pdf",
416-
header: '<style>... custom css classes here ...</style>'
416+
header: '<style>... custom css classes here ...</style>'
417417
});
418418
~~~
419419

@@ -432,27 +432,30 @@ For more examples, check the [How to add resource chart or custom styles in the
432432

433433
### Collecting all styles for the export function
434434

435-
Sometimes styles are specified in different files unavailable for public access, and it is unhandy to include styles from each of them separately. There is a way to collect all styles together for export.
435+
Sometimes styles are specified in different files unavailable for public access, and it is unhandy to include styles from each of them separately. There is a way to collect all styles together for export.
436436

437437
All styles are stored in the **document.styleSheets** object on an HTML page. If the *style* or *link* element included from the same site is used, you can collect all of them and then specify in the **header**. Check the example below:
438438

439439
~~~js
440-
const styles = []
441-
for (el in document.styleSheets) {
440+
const styles = [];
441+
442+
for (const styleSheet of document.styleSheets) {
442443
try {
443-
const rules = (document.styleSheets[el]).cssRules;
444-
for (rule in rules) {
445-
styles.push(rules[rule].cssText)
444+
const rules = styleSheet.cssRules;
445+
446+
for (const rule of rules) {
447+
styles.push(rule.cssText);
446448
}
449+
} catch (error) {
450+
// Ignore stylesheets that cannot be read
447451
}
448-
catch (e) { }
449452
}
450453

451454
gantt.exportToPDF({
452455
raw: true,
453456
header: "<style>" + styles.join(" ") + "</style>"
454457
});
455-
~~~
458+
~~~
456459

457460
**Related sample**: [Export Gantt with custom icons to PDF](https://snippet.dhtmlx.com/osbscj62)
458461

@@ -462,7 +465,7 @@ gantt.exportToPDF({
462465
## Exporting custom markup and styles {#exportingcustommarkupandstyles}
463466

464467
By default the Gantt chart is exported based on the specified configuration and loaded data, while [custom elements](guides/baselines.md) and some templates are not exported.
465-
To export the whole gantt markup as it is, with all custom elements, you can set the **raw:true** property in the parameter of the [exportToPDF/exportToPNG](guides/export.md#parameters-of-the-export-methods) methods.
468+
To export the whole gantt markup as it is, with all custom elements, you can set the **raw: true** property in the parameter of the [exportToPDF/exportToPNG](guides/export.md#parameters-of-the-export-methods) methods.
466469

467470
~~~js
468471
gantt.exportToPDF({
@@ -473,14 +476,14 @@ gantt.exportToPDF({
473476
Note that custom elements will require providing [custom styles](guides/export.md#customstylefortheoutputfile) in order to be displayed correctly.
474477

475478
Pay attention that the use of this mode increases the size of the API request. Large charts can exceed limit of the online export of 10MB and may not be exported that way.
476-
In such a case you need to have an [export service](https://dhtmlx.com/docs/products/dhtmlxGantt/export.shtml) installed locally and increase the request size.
479+
In such a case you need to have an [export service](https://dhtmlx.com/docs/products/dhtmlxGantt/export.shtml) installed locally and increase the request size.
477480

478481

479482
Check [system requirements](guides/export-requirements.md) to install export services locally.
480483

481484
## Exporting HTML elements
482485

483-
While exporting the Gantt chart to the PNG and PDF formats, you should note that export of HTML elements is limited due to their possible insecurity.
486+
While exporting the Gantt chart to the PNG and PDF formats, you should note that export of HTML elements is limited due to their possible insecurity.
484487

485488
There are HTML elements which are not entirely allowed for export, such as `<canvas>`, `<svg>`, `<script>` and images with the *src* attribute that contains a Base64 image. However, there are safe ways of exporting images in the SVG and Base64 formats:
486489

@@ -504,4 +507,3 @@ There are HTML elements which are not entirely allowed for export, such as `<can
504507
**Related sample**: [Exporting safe and insecure HTML elements to PDF](https://snippet.dhtmlx.com/hj6w4dk3?text="gantt")
505508

506509
If you have an export module and you need to export HTML elements that are not supported by our online export server, you can submit a support request to get instructions on the changes you need to make in your module to remove restrictions. However, you should take into account that your server will be vulnerable to XSS-attacks.
507-

0 commit comments

Comments
 (0)