- File name for exported document
- How to change page orientation
- How to change page size
- Export current view data
- Export hidden columns
- Export predecessor lines
- Show or hide columns on exported PDF
- Conditional cell formatting
- Timeline cell formatting
- Taskbar formatting
- Customize Gantt Chart Appearance in PDF Export
- Customize Split Taskbar Segment Colors in PDF
- Exporting with templates
Contact Support
To customize PDF export
25 Mar 202524 minutes to read
PDF export provides an option to customize the mapping of Gantt to exported PDF document.
File name for exported document
The file name of the exported PDF document can be specified using the fileName property in pdfExportProperties.
var clickHandler = function(args){
if (args.item.id === 'GanttExport_pdfexport') {
var exportProperties = {
fileName:"new.pdf"
};
ganttChart.pdfExport(exportProperties);
}
};
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
allowPdfExport: true,
toolbar: ['PdfExport'],
toolbarClick: clickHandler
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
How to change page orientation
The page orientation of the exported PDF document can be customized using the [pageOrientation]
(../../api/gantt/pdfExportProperties/#pageorientation) property in pdfExportProperties. By default, the exported PDF document is in Landscape orientation.
var clickHandler = function(args){
if (args.item.id === 'GanttExport_pdfexport') {
var exportProperties = {
pageOrientation: 'Portrait'
};
ganttChart.pdfExport(exportProperties);
}
};
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
allowPdfExport: true,
toolbar: ['PdfExport'],
toolbarClick: clickHandler
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
How to change page size
Page size can be customized for the exported document using the pageSize property in pdfExportProperties.
The supported page sizes are:
- Letter
- Note
- Legal
- A0
- A1
- A2
- A3
- A5
- A6
- A7
- A8
- A9
- B0
- B1
- B2
- B3
- B4
- B5
- Archa
- Archb
- Archc
- Archd
- Arche
- Flsa
- HalfLetter
- Letter11x17
- Ledger
var clickHandler = function(args){
if (args.item.id === 'GanttExport_pdfexport') {
var exportProperties = {
pageSize: 'A0'
};
ganttChart.pdfExport(exportProperties);
}
};
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
allowPdfExport: true,
toolbar: ['PdfExport'],
toolbarClick: clickHandler
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Export current view data
PDF export provides an option to export the current view data into PDF. To export current view data alone, define the exportType to CurrentViewData
.
var clickHandler = function(args){
if (args.item.id === 'GanttExport_pdfexport') {
var exportProperties = {
exportType: 'CurrentViewData'
};
ganttChart.pdfExport(exportProperties);
}
};
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height: '450px',
allowFiltering: true,
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
allowPdfExport: true,
toolbar: ['PdfExport'],
toolbarClick: clickHandler
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Export hidden columns
PDF export provides an option to export hidden columns of Gantt by defining the includeHiddenColumn to true
.
var clickHandler = function(args){
if (args.item.id === 'GanttExport_pdfexport') {
var exportProperties = {
includeHiddenColumn: true
};
ganttChart.pdfExport(exportProperties);
}
};
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
columns: [
{ field: 'TaskID'},
{ field: 'TaskName', visible: false},
{ field: 'StartDate'},
{ field: 'Duration'},
{ field: 'Progress'}
],
allowPdfExport: true,
toolbar: ['PdfExport'],
toolbarClick: clickHandler
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Export predecessor lines
The visibility of predecessor lines in the exported PDF document can be controlled using the showPredecessorLines property.
var clickHandler = function(args){
if (args.item.id === 'GanttExport_pdfexport') {
var exportProperties = {
showPredecessorLines: true
};
ganttChart.pdfExport(exportProperties);
}
};
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
allowPdfExport: true,
toolbar: ['PdfExport'],
toolbarClick: clickHandler
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Show or hide columns on exported PDF
A hidden column can be shown, or a visible column can be hidden while exporting the Gantt chart by using the toolbarClick
and beforePdfExport
events.
Columns can be shown or hidden by setting the column.visible
property to true or false, respectively.
In the following example, the Duration
column is initially hidden in the Gantt chart. During export, the Duration
column is made visible and the StartDate column is hidden.
var clickHandler = function(args){
if (args.item.id === 'GanttExport_pdfexport') {
ganttChart.pdfExport();
}
};
var beforePdfExport = function(args){
ganttChart.treeGrid.columns[2].visible = false;
ganttChart.treeGrid.columns[3].visible = true;
};
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskId',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
dependency: 'Predecessor',
parentID:'ParentId',
},
columns: [
{ field: 'TaskId'},
{ field: 'TaskName'},
{ field: 'StartDate'},
{ field: 'Duration', visible: false},
{ field: 'Progress'}
],
allowPdfExport: true,
toolbar: ['PdfExport'],
toolbarClick: clickHandler,
beforePdfExport: beforePdfExport
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Conditional cell formatting
TreeGrid cells in the exported PDF can be customized or formatted using the pdfQueryCellInfo
event. This event allows formatting TreeGrid cells in the exported PDF document based on the column cell value.
In the following sample, the background color is set for Progress
column in the exported document by using the args.style.backgroundColor
property.
var clickHandler = function(args){
if (args.item.id === 'GanttExport_pdfexport') {
ganttChart.pdfExport();
}
};
var pdfQueryCellInfo = function(args){
if(args.column.field == 'Progress'){
if(args.value < 50) {
args.style.backgroundColor = new ej.pdfexport.PdfColor(240, 128, 128);
} else {
args.style.backgroundColor = new ej.pdfexport.PdfColor(165, 105, 189);
}
}
};
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskId',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID:'ParentId'
},
columns: [
{ field: 'TaskId'},
{ field: 'TaskName'},
{ field: 'StartDate'},
{ field: 'Duration', visible: false},
{ field: 'Progress'}
],
allowPdfExport: true,
toolbar: ['PdfExport'],
toolbarClick: clickHandler,
pdfQueryCellInfo: pdfQueryCellInfo
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Timeline cell formatting
Timeline cells in the exported PDF document can be customized or formatted using the pdfQueryTimelineCellInfo
event.
In the following sample, the header background color is set for timeline cells in the exported document by using the args.headerBackgroundColor
property.
var clickHandler = function(args){
if (args.item.id === 'GanttExport_pdfexport') {
ganttChart.pdfExport();
}
};
var pdfQueryTimelineCellInfo = function(args){
if(args.column.field == 'Progress'){
args.timelineCell.backgroundColor = new ej.pdfexport.PdfColor(240, 248, 255);
}
};
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
columns: [
{ field: 'TaskID'},
{ field: 'TaskName'},
{ field: 'StartDate'},
{ field: 'Duration', visible: false},
{ field: 'Progress'}
],
allowPdfExport: true,
toolbar: ['PdfExport'],
toolbarClick: clickHandler,
pdfQueryTimelineCellInfo: pdfQueryTimelineCellInfo
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Taskbar formatting
Taskbars in the exported PDF document can be customized or formatted using the pdfQueryTaskbarInfo
event.
In the following sample, the taskbar background color is customized in the chart side of the exported document by using the args.taskbar
property.
var clickHandler = function(args){
if (args.item.id === 'GanttExport_pdfexport') {
ganttChart.pdfExport();
}
};
var pdfQueryTaskbarInfo = function(args){
if(args.data.Progress < 50 && !args.data.hasChildRecords) {
args.taskbar.progressColor = new ej.pdfexport.PdfColor(205, 92, 92);
args.taskbar.taskColor = args.taskbar.taskBorderColor = new ej.pdfexport.PdfColor(240, 128, 128);
}
};
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
columns: [
{ field: 'TaskID'},
{ field: 'TaskName'},
{ field: 'StartDate'},
{ field: 'Duration', visible: false},
{ field: 'Progress'}
],
allowPdfExport: true,
toolbar: ['PdfExport'],
toolbarClick: clickHandler,
pdfQueryTaskbarInfo: pdfQueryTaskbarInfo
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Customize Gantt Chart Appearance in PDF Export
PDF export allows to customize the Gantt chart’s appearance in the exported PDF documents. To customize the appearance of Gantt charts in exported PDF documents, define ganttStyle within pdfExportProperties. By using ganttStyle
, can customize columnHeader
, fontFamily
, cell
, taskbar
, label
, timeline
, chartGridLineColor
, connectorLineColor
, criticalConnectorLineColor
, footer
, font
, eventMarker
and holiday
regardless of the theme.
var clickHandler = function(args){
if (args.item.id === 'GanttExport_pdfexport') {
const stringFormat = new ej.pdfexport.PdfStringFormat();
stringFormat.alignment = ej.pdfexport.PdfTextAlignment.Center;
const vertical = new ej.pdfexport.PdfStringFormat();
vertical.alignment = ej.pdfexport.PdfTextAlignment.Center;
const penColor = new ej.pdfexport.PdfColor(105, 105, 105);
const penWidth = 1;
const pen = new ej.pdfexport.PdfPen(penColor, penWidth);
pen.dashStyle = ej.pdfexport.PdfDashStyle.Dash;
const borderWidth = 1;
const borderColor = new ej.pdfexport.PdfColor(192, 192, 192);
let pdfpen = new ej.pdfexport.PdfPen(borderColor, borderWidth);
let pdfborders = new ej.pdfexport.PdfBorders();
pdfborders.all = pdfpen;
var exportProperties = {
ganttStyle: {
fontFamily: 1,
columnHeader: {
backgroundColor: new ej.pdfexport.PdfColor(179, 219, 255)
},
taskbar: {
taskColor: new ej.pdfexport.PdfColor(240, 128, 128),
taskBorderColor: new ej.pdfexport.PdfColor(240, 128, 128),
progressColor: new ej.pdfexport.PdfColor(205, 92, 92),
},
connectorLineColor: new ej.pdfexport.PdfColor(128,0,0),
footer: {
backgroundColor: new ej.pdfexport.PdfColor(205, 92, 92)
},
timeline: {
backgroundColor: new ej.pdfexport.PdfColor(179, 219, 255),
fontStyle: 1
},
label: {
fontColor: new ej.pdfexport.PdfColor(128, 0, 0),
},
cell: {
backgroundColor: new ej.pdfexport.PdfColor(240, 248, 255),
fontColor: new ej.pdfexport.PdfColor(0, 0, 0),
borderColor:new ej.pdfexport.PdfColor(179, 219, 255),
},
eventMarker: {
label: {
backgroundColor: new ej.pdfexport.PdfColor(255, 239, 213),
fontFamily: ej.pdfexport.PdfFontFamily.TimesRoman,
fontColor: new ej.pdfexport.PdfColor(139, 69, 19),
fontSize: 9,
format: stringFormat,
fontStyle: ej.pdfexport.PdfFontStyle.Bold,
borderColor: new ej.pdfexport.PdfColor(160, 82, 45),
borders: pdfborders,
},
lineStyle: pen,
},
holiday: {
fontFamily: ej.pdfexport.PdfFontFamily.TimesRoman,
fontSize: 10,
fontStyle: ej.pdfexport.PdfFontStyle.Bold,
borderColor: new ej.pdfexport.PdfColor(211, 211, 211),
backgroundColor: new ej.pdfexport.PdfColor(255, 248, 220),
fontColor: new ej.pdfexport.PdfColor(105, 105, 105),
format: vertical,
borders: pdfborders,
},
}
};
ganttChart.pdfExport(exportProperties);
}
};
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
allowPdfExport: true,
toolbar: ['PdfExport'],
toolbarClick: clickHandler,
eventMarkers: [
{
day: '04/10/2019',
cssClass: 'e-custom-event-marker',
label: 'Project approval and kick-off'
}
],
holidays: [{
from: "04/04/2019",
to: "04/04/2019",
label: " Public holidays",
cssClass: "e-custom-holiday"
},
{
from: "04/12/2019",
to: "04/12/2019",
label: " Public holiday",
cssClass: "e-custom-holiday"
}],
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Customize Split Taskbar Segment Colors in PDF
The PDF export feature in the Gantt Chart allows you to customize the colors of split taskbar segments using the taskSegmentStyles
property inside the pdfQueryTaskbarInfo
event.
The taskSegmentStyles
property contains a collection of style properties for task segments. By specifying the index of corresponding segment index in this collection you can customize that segment taskbar color, progress color, and its border color.
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
taskFields: {
id: "TaskID",
name: "TaskName",
startDate: "StartDate",
endDate: "EndDate",
duration: "Duration",
progress: "Progress",
child: "subtasks",
segments: "Segments"
},
editSettings: {
allowEditing: true,
allowDeleting: true,
allowTaskbarEditing: true,
showDeleteConfirmDialog: true
},
toolbar: ['PdfExport'],
toolbarClick: (args) => {
if (args.item.id === 'GanttExport_pdfexport') {
ganttChart.pdfExport();
}
},
columns: [
{ field: 'TaskID', headerText: 'Task ID' },
{ field: 'TaskName', headerText: 'Task Name' },
{ field: 'StartDate', headerText: 'Start Date' },
{ field: 'EndDate', headerText: 'End Date' },
],
allowPdfExport: true,
gridLines: "Both",
showColumnMenu: false,
queryTaskbarInfo: (args) => {
if (args.data.taskData.Segments) {
var segmentIndex = args.taskbarElement.dataset.segmentIndex;
if (Number(segmentIndex) === 1) {
args.taskbarBgColor = 'red';
args.taskbarBorderColor = 'black';
args.progressBarBgColor = "green";
}
}
},
height: "450px",
pdfQueryTaskbarInfo: (args) => {
if (args.taskbar.taskSegmentStyles) {
args.taskbar.taskSegmentStyles[1].taskColor = new ej.pdfexport.PdfColor(255, 0, 0);
args.taskbar.taskSegmentStyles[1].progressColor = new ej.pdfexport.PdfColor(0, 128, 0);
args.taskbar.taskSegmentStyles[1].taskBorderColor = new ej.pdfexport.PdfColor(0, 0, 0);
}
},
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Exporting with templates
Exporting with column template
The PDF export functionality allows to export Grid columns that include images, hyperlinks, and custom text to an PDF document using pdfQueryCellInfo event.
In the following sample, the hyperlinks and images are exported to PDF using hyperlink and image properties in the pdfQueryCellInfo event.
Note: PDF Export supports base64 string to export the images.
var clickHandler = function(args){
if (args.item.id === 'GanttExport_pdfexport') {
var exportProperties = {
enableFooter: false
};
ganttChart.pdfExport(exportProperties);
}
};
function pdfQueryCellInfo(args) {
if (args.column.headerText === 'Resources') {
{
args.image = { height: 40, width: 40, base64: args.data.taskData.resourcesImage };
}
}
if (args.column.headerText === 'Email ID') {
args.hyperLink = {
target: 'mailto:' + args.data.taskData.EmailId,
displayText: args.data.taskData.EmailId
};
}
}
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate: 'EndDate',
duration: 'Duration',
progress: 'Progress',
resourceInfo: 'resources',
dependency: 'Predecessor',
child: 'subtasks'
},
allowPdfExport: true,
columns: [
{ field: 'TaskID', headerText: 'Task ID', textAlign: 'Left' },
{ field: 'TaskName', headerText: 'Task Name', width: '250' },
{ field: 'resources', headerText: 'Resources', width: '250', template: '#columnTemplate' },
{field: 'EmailId', headerText: 'Email ID', template: '#template2', width: 180 },
],
pdfQueryCellInfo: pdfQueryCellInfo,
toolbar: ['PdfExport'],
toolbarClick: clickHandler,
resources: editingResources,
resourceFields: {
id: 'resourceId',
name: 'resourceName'
},
projectStartDate: new Date('03/24/2019'),
projectEndDate: new Date('07/06/2019')
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<script type="text/x-jsrender" id="columnTemplate">
${if(ganttProperties.resourceNames)}
<div class="image">
<img src="./images/${ganttProperties.resourceNames}.png" style="height:40px;width:40px" alt="${resourceName}" />
</div>
${/if}
</script>
<script id="template2" type="text/x-template">
${if(taskData.EmailId)}
<div class="link">
<a href="mailto:${taskData.EmailId}">${taskData.EmailId}</a></div>
</div>
${/if}
</script>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>
Exporting with taskbar template
The PDF export functionality allows to export taskbar templates that include images
and text
to an PDF document using pdfQueryTaskbarInfo event. Taskbars in the exported PDF document can be customized or formatted using the pdfQueryTaskbarInfo
event for parent taskbar template, taskbar templates and milestone templates.
In the following sample, taskbar templates with images and text are exported to PDF using taskbarTemplate properties in the pdfQueryTaskbarInfo event.
Note: PDF Export supports base64 string to export the images.
var clickHandler = function (args) {
if (args.item.id === 'GanttExport_pdfexport') {
var exportProperties = {
enableFooter: false
};
ganttChart.pdfExport(exportProperties);
}
};
var pdfQueryTaskbarInfo = function(args){
if (!args.data.hasChildRecords) {
if (args.data.ganttProperties.resourceNames) {
args.taskbarTemplate.image = [{
width: 20, base64: (args).data.taskData.resourcesImage, height: 20
}]
}
args.taskbarTemplate.value = args.data.TaskName;
}
if (args.data.hasChildRecords) {
if (args.data.ganttProperties.resourceNames) {
args.taskbarTemplate.image = [{
width: 20, base64: (args).data.taskData.resourcesImage, height: 20
}]
}
args.taskbarTemplate.value = args.data.TaskName;
}
if (args.data.ganttProperties.duration === 0) {
if (args.data.ganttProperties.resourceNames) {
args.taskbarTemplate.image = [{
width: 20, base64: (args).data.taskData.resourcesImage, height: 20,
}]
}
args.taskbarTemplate.value = args.data.TaskName
}
};
var ganttChart = new ej.gantt.Gantt({
dataSource: ganttData,
height: '450px',
rowHeight: 55,
taskbarHeight: 45,
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate: 'EndDate',
duration: 'Duration',
resourceInfo: 'resources',
dependency: 'Predecessor',
child: 'subtasks'
},
allowPdfExport: true,
columns: [
{ field: 'TaskID', headerText: 'Task ID', textAlign: 'Left' },
{ field: 'TaskName', headerText: 'Task Name', width: '250' },
],
pdfQueryTaskbarInfo: pdfQueryTaskbarInfo,
toolbar: ['PdfExport'],
toolbarClick: clickHandler,
resources: editingResources,
resourceFields: {
id: 'resourceId',
name: 'resourceName'
},
milestoneTemplate: '#MilestoneTemplate',
parentTaskbarTemplate: '#ParentTaskbarTemplate',
taskbarTemplate: '#TaskbarTemplate',
projectStartDate: new Date('03/24/2019'),
projectEndDate: new Date('04/30/2019'),
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<script type="text/x-jsrender" id="TaskbarTemplate">
<div class="e-gantt-child-taskbar-inner-div e-gantt-child-taskbar" style="height:100%">
<div class="e-gantt-child-progressbar-inner-div e-gantt-child-progressbar" style="width:${ganttProperties.progressWidth}px;height:100%">
${if(ganttProperties.resourceNames)}
<div class="image">
<img src="./images/${ganttProperties.resourceNames}.png" style="height:40px;width:40px" alt="${resourceName}" />
</div>
${/if}
<span class="e-task-label" style="position: absolute; z-index: 1; max-width:70%; font-size: 12px; color: white; top: 5px; left: 35px; font-family: "Segoe UI"; overflow: hidden; text-overflow: ellipsis; width: 40%; cursor: move;">${taskData.TaskName}</span>
</div>
</div>
</script>
<script type="text/x-jsrender" id="ParentTaskbarTemplate">
<div class="e-gantt-parent-taskbar-inner-div e-gantt-parent-taskbar" style="height:100%">
<div class="e-gantt-parent-progressbar-inner-div e-gantt-parent-progressbar" style="width:${ganttProperties.progressWidth}px;height:100%">
<span class="e-task-label" style="position: absolute; z-index: 1; font-size: 12px; color: white; top: 5px; left: 10px; font-family: "Segoe UI"; overflow: hidden; text-overflow: ellipsis; width: 40%; cursor: move;">${taskData.TaskName}</span>
</div>
</div>
</script>
<script type="text/x-jsrender" id="MilestoneTemplate">
<div style="margin-top=-7px;">
<div class="e-gantt-milestone" style="position:absolute;">
<div class="image" style="position:absolute; left: 6px ; top: 5px">
<img class="moments" src="images/${ganttProperties.resourceNames}.png" height="40px" width="40px" />
</div>
<div class="e-milestone-top" style="border-right-width:20px; margin-top: -2px;border-left-width:20px;border-bottom-width:20px;"></div>
<div class="e-milestone-bottom" style="top:26px;border-right-width:20px; border-left-width:20px; border-top-width:20px;"></div>
</div>
</div>
</script>
</script>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>
Exporting with task label template
The PDF export functionality allows to export task label template that include images
and text
to an PDF document using pdfQueryTaskbarInfo event.
In the following sample, task label template with images and text are exported to PDF using labelSettings properties in the pdfQueryTaskbarInfo event.
Note: PDF Export supports base64 string to export the images.
var clickHandler = function (args) {
if (args.item.id === 'GanttExport_pdfexport') {
var exportProperties = {
enableFooter: false
};
ganttChart.pdfExport(exportProperties);
}
};
var pdfQueryTaskbarInfo = function(args){
args.labelSettings.leftLabel.value = args.data.ganttProperties.taskName + '[' + args.data.ganttProperties.progress + ']';
if (args.data.ganttProperties.resourceNames) {
args.labelSettings.rightLabel.value = args.data.ganttProperties.resourceNames;
args.labelSettings.rightLabel.image = [{
base64: args.data.taskData.resourcesImage, width: 20, height: 20
}];
}
args.labelSettings.taskLabel.value = args.data.ganttProperties.progress + '%';
}
window.getResourceElements = function (value) {
var out = "";
var img = document.createElement('img');
img.height = 20;
var span = document.createElement('span');
span.style.marginLeft = "5px";
span.style.marginRight = "5px";
for (var index = 0; index < value.length; index++) {
img.src = 'https://ej2.syncfusion.com/demos/src/gantt/images/' + value[index].resourceName + '.png';
span.innerHTML = value[index].resourceName;
out = out + img.outerHTML + span.outerHTML;
}
return out;
};
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height: '450px',
rowHeight: 55,
taskbarHeight: 45,
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate: 'EndDate',
duration: 'Duration',
progress: 'Progress',
resourceInfo: 'resources',
dependency: 'Predecessor',
child: 'subtasks'
},
allowPdfExport: true,
columns: [
{ field: 'TaskID', headerText: 'Task ID', textAlign: 'Left' },
{ field: 'TaskName', headerText: 'Task Name', width: '250' },
],
pdfQueryTaskbarInfo: pdfQueryTaskbarInfo,
toolbar: ['PdfExport'],
toolbarClick: clickHandler,
resources: editingResources,
resourceFields: {
id: 'resourceId',
name: 'resourceName'
},
labelSettings: {
leftLabel: '#leftLabel',
rightLabel: '#rightLabel',
taskLabel: '${Progress}%'
},
projectStartDate: new Date('03/24/2019'),
projectEndDate: new Date('04/30/2019'),
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<script type="text/x-template" id="leftLabel">
<div style="margin-top=-7px;">
<div id = "leftLabel">
<span>${TaskName} [ ${TaskID}]</span>
</div>
</div>
</script>
<script type="text/x-template" id="rightLabel">
<div style="margin-top=-7px;">
${if(ganttProperties.resourceInfo)}
<div id = "rightLabel">
${getResourceElements(ganttProperties.resourceInfo)}
</div>
${/if}
</div>
</script>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>
Exporting with header template
The PDF export functionality allows to export header template that include images
and text
to an PDF document using pdfColumnHeaderQueryCellInfo event.
In the following sample, header template with images and text are exported to PDF using headerTemplate properties in the pdfColumnHeaderQueryCellInfo event.
Note: PDF Export supports base64 string to export the images.
var clickHandler = function (args) {
if (args.item.id === 'GanttExport_pdfexport') {
var exportProperties = {
enableFooter: false
};
ganttChart.pdfExport(exportProperties);
}
};
var i = 0;
var pdfColumnHeaderQueryCellInfo = function (args) {
var base64Array = [
{ 'TaskName': '/9j/4AAQSkZJRgABAQIAHAAcAAD/4QBiRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAMAAAITAAMAAAABAAEAAAAAAAAAAAAcAAAAAQAAABwAAAAB/9sAQwADAgICAgIDAgICAwMDAwQGBAQEBAQIBgYFBgkICgoJCAkJCgwPDAoLDgsJCQ0RDQ4PEBAREAoMEhMSEBMPEBAQ/9sAQwEDAwMEAwQIBAQIEAsJCxAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ/8AAEQgAIAAgAwERAAIRAQMRAf/EABgAAQEBAQEAAAAAAAAAAAAAAAYIAAcF/8QALBAAAQQCAgEDAwIHAAAAAAAAAQIDBAUGBxESAAgTIRQVQRYxFzhXdpa01f/EABQBAQAAAAAAAAAAAAAAAAAAAAD/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwB7gessOlaiw2zpdS4Ld2cqngOyl2rLbHcqjpLiy6IzylL7/gp/J+RxwQQt68w6mewu7XrfEKC+azXGuiqiO2r2ybqKnhD3stLVy2TyOg/cj5A5IXr4G8Cf9+aD0XT6K2Nb1GlsEgz4OJW8mLKjY5DaeYdRDdUhxC0thSVJUAQoEEEAjwNW2XoFprGLb1E/QEGdBeRJiyoztK08w6hQUhxC0kFKkqAIUCCCAR4CDD9sbV2RWSso19r3BrDGza2NfWWEnOH21T2Yst2MJKUs1ryAhwslSeHFfBHyRwSHnW26tv12qpO5Ier8GtMdYoVZI2qJm01L0iCGPfC0IeqEcKLfyErKT+DwfjwFvqO/l62h/Zl3/oveB0TwJTe2FRYxX5RqrLrj065HUuZRdzXIOQ7GRHc6yLV+YlmVDcgPJS6044AQVHhTY/I58Ao3lmJUeibfRWBZH6bKCFbUL1K7PTtRpTrzjsQRlzJCWqxoPyFISkqWepUQOfj48Ctdj4j/ABA15lGB/cPoP1JSzaj6v2vd+n+oYW17nTsnv1789ew5445H7+Ad+x+oX+qGu/8AA53/AGPA5drHb+D4rru/xSy3nrPG86i5hkwnOXDjbTIkG9lrU4qCqY271W0R0BfJSFI5UvqQQKWW5cOT6NMhxTZO+9d5Fl72ByIYjQrmM9LMo1oQll0iXIMuSH+3Z9BSlaiFBCeOSH//2Q==' },
];
while (i < base64Array.length) {
var key = Object.keys(base64Array[i])[0];
var value = base64Array[i][key];
if (key === args.column.field) {
args.headerTemplate.image = [{
base64: value, width: 20, height: 20
}];
args.headerTemplate.value = args.column.field;
break;
}
i++;
}
};
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height: '450px',
rowHeight: 45,
taskbarHeight: 35,
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate: 'EndDate',
duration: 'Duration',
progress: 'Progress',
resourceInfo: 'resources',
dependency: 'Predecessor',
child: 'subtasks'
},
allowPdfExport: true,
columns: [
{ field: 'TaskName', headerTemplate: '#projectName', width: 250 },
{ field: 'StartDate', headerTemplate: '#dateTemplate' }
],
pdfColumnHeaderQueryCellInfo: pdfColumnHeaderQueryCellInfo,
toolbar: ['PdfExport'],
toolbarClick: clickHandler,
resources: editingResources,
resourceFields: {
id: 'resourceId',
name: 'resourceName'
},
projectStartDate: new Date('03/24/2019'),
projectEndDate: new Date('04/30/2019'),
});
ganttChart.appendTo('#GanttExport');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<script type="text/x-template" id="projectName">
<div>
<div>
<img class="taskName" src="images/Task name.png" width="20" height="20" /> Task Name
</div>
</div>
</script>
<script type="text/x-template" id="dateTemplate">
<div>
<div>
<img class="startDate" src="images/Start date.png" width="20" height="20" /> Start Date
</div>
</div>
</script>
<div id="container">
<div id="GanttExport"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>