- File name for exported document
- How to change page orientation
- How to change page size
- Export current view data
- Enable footer
- 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
17 May 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.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { ToolbarService, PdfExportService, SelectionService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { Gantt } from '@syncfusion/ej2-gantt';
import { GanttComponent, ToolbarItem, PdfExport, Selection, PdfExportProperties } from '@syncfusion/ej2-angular-gantt';
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import { SelectionSettingsModel } from '@syncfusion/ej2-angular-grids';
import { editingData } from './data';
@Component({
imports: [
GanttModule
],
providers: [ToolbarService, PdfExportService, SelectionService],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt #gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [toolbar]="toolbar"
(toolbarClick)="toolbarClick($event)" allowPdfExport='true' [treeColumnIndex]="1"></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public toolbar?: ToolbarItem[];
@ViewChild('gantt', {static: true})
public ganttChart?: GanttComponent;
public ngOnInit(): void {
this.data = editingData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID:'ParentID',
};
this.toolbar = ['PdfExport'];
}
public toolbarClick(args: ClickEventArgs): void {
if (args.item.id === 'ganttDefault_pdfexport') {
let exportProperties: PdfExportProperties = {
fileName:"new.pdf"
};
this.ganttChart!.pdfExport(exportProperties);
}
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
How to change page orientation
The page orientation of the exported PDF document can be customized using the pageOrientation property in pdfExportProperties. By default, the exported PDF document is in Landscape orientation.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { ToolbarService, PdfExportService, SelectionService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { Gantt, Toolbar, PdfExport, Selection, PdfExportProperties, ToolbarItem, GanttComponent } from '@syncfusion/ej2-angular-gantt';
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import { SelectionSettingsModel } from '@syncfusion/ej2-angular-grids';
import { editingData } from './data';
@Component({
imports: [
GanttModule
],
providers: [ToolbarService, PdfExportService, SelectionService],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt #gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [toolbar]="toolbar"
(toolbarClick)="toolbarClick($event)" allowPdfExport='true' [treeColumnIndex]="1"></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public toolbar?: ToolbarItem[];
@ViewChild('gantt', {static: true})
public ganttChart?: GanttComponent;
public ngOnInit(): void {
this.data = editingData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID:'ParentID',
};
this.toolbar = ['PdfExport'];
}
public toolbarClick(args: ClickEventArgs): void {
if (args.item.id === 'ganttDefault_pdfexport') {
let exportProperties: PdfExportProperties = {
pageOrientation: 'Portrait'
};
this.ganttChart!.pdfExport(exportProperties);
}
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { ToolbarService, PdfExportService, SelectionService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { Gantt, Toolbar, PdfExport, Selection, PdfExportProperties, ToolbarItem, GanttComponent } from '@syncfusion/ej2-angular-gantt';
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import { SelectionSettingsModel } from '@syncfusion/ej2-angular-grids';
import { editingData } from './data';
@Component({
imports: [
GanttModule
],
providers: [ToolbarService, PdfExportService, SelectionService],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt #gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [toolbar]="toolbar"
(toolbarClick)="toolbarClick($event)" allowPdfExport='true' [treeColumnIndex]="1"></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public toolbar?: ToolbarItem[];
@ViewChild('gantt', {static: true})
public ganttChart?: GanttComponent;
public ngOnInit(): void {
this.data = editingData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID:'ParentID',
};
this.toolbar = ['PdfExport'];
}
public toolbarClick(args: ClickEventArgs): void {
if (args.item.id === 'ganttDefault_pdfexport') {
let exportProperties: PdfExportProperties = {
pageSize: 'A0'
};
this.ganttChart!.pdfExport(exportProperties);
}
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { ToolbarService, PdfExportService, SelectionService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { Gantt, Toolbar, PdfExport, Selection, Filter, PdfExportProperties, ToolbarItem, GanttComponent } from '@syncfusion/ej2-angular-gantt';
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import { SelectionSettingsModel } from '@syncfusion/ej2-angular-grids';
import { editingData } from './data';
@Component({
imports: [
GanttModule
],
providers: [ToolbarService, PdfExportService, SelectionService],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt #gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [toolbar]="toolbar"
(toolbarClick)="toolbarClick($event)" allowPdfExport='true' [treeColumnIndex]="1"></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public toolbar?: ToolbarItem[];
@ViewChild('gantt', {static: true})
public ganttChart?: GanttComponent;
public ngOnInit(): void {
this.data = editingData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID:'ParentID',
};
this.toolbar = ['PdfExport'];
}
public toolbarClick(args: ClickEventArgs): void {
if (args.item.id === 'ganttDefault_pdfexport') {
let exportProperties: PdfExportProperties = {
exportType: 'CurrentViewData'
};
this.ganttChart!.pdfExport(exportProperties);
}
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Enable footer
By default, we render the default footer for a PDF file, this can be enabled or disabled by using the enableFooter
property.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { ToolbarService, PdfExportService, SelectionService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { Gantt, Toolbar, PdfExport, Selection, PdfExportProperties, ToolbarItem, GanttComponent } from '@syncfusion/ej2-angular-gantt';
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import { SelectionSettingsModel } from '@syncfusion/ej2-angular-grids';
import { editingData } from './data';
@Component({
imports: [
GanttModule
],
providers: [ToolbarService, PdfExportService, SelectionService],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt #gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [toolbar]="toolbar"
(toolbarClick)="toolbarClick($event)" allowPdfExport='true' [treeColumnIndex]="1"></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public toolbar?: ToolbarItem[];
@ViewChild('gantt', {static: true})
public ganttChart?: GanttComponent;
public ngOnInit(): void {
this.data = editingData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID:'ParentID',
};
this.toolbar = ['PdfExport'];
}
public toolbarClick(args: ClickEventArgs): void {
if (args.item.id === 'ganttDefault_pdfexport') {
let exportProperties: PdfExportProperties = {
enableFooter: false
};
this.ganttChart!.pdfExport(exportProperties);
}
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Export hidden columns
PDF export provides an option to export hidden columns of Gantt by defining the includeHiddenColumn to true
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { ToolbarService, PdfExportService, SelectionService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { Gantt, Toolbar, PdfExport, Selection, PdfExportProperties, ToolbarItem, GanttComponent } from '@syncfusion/ej2-angular-gantt';
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import { SelectionSettingsModel } from '@syncfusion/ej2-angular-grids';
import { editingData } from './data';
@Component({
imports: [
GanttModule
],
providers: [ToolbarService, PdfExportService, SelectionService],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt #gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [columns]="columns" [toolbar]="toolbar"
(toolbarClick)="toolbarClick($event)" allowPdfExport='true' [treeColumnIndex]="1"></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public toolbar?: ToolbarItem[];
@ViewChild('gantt', {static: true})
public ganttChart?: GanttComponent;
columns: ({ field: string; headerText: string; textAlign: string; width: string; visible?: undefined; } | { field: string; headerText: string; width: string; visible: boolean; textAlign?: undefined; } | { field: string; headerText: string; width: string; textAlign?: undefined; visible?: undefined; })[] | undefined;
public ngOnInit(): void {
this.data = editingData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID:'ParentID',
};
this.columns = [
{ field: 'TaskID', headerText: 'Task ID', textAlign: 'Left', width: '100' },
{ field: 'TaskName', headerText: 'Task Name', width: '150', visible: false },
{ field: 'StartDate', headerText: 'StartDate', width: '150' },
{ field: 'Duration', headerText: 'Duration', width: '150' },
{ field: 'Progress', headerText: 'Progress', width: '150' }
];
this.toolbar = ['PdfExport'];
}
public toolbarClick(args: ClickEventArgs): void {
if (args.item.id === 'ganttDefault_pdfexport') {
let exportProperties: PdfExportProperties = {
includeHiddenColumn: true
};
this.ganttChart!.pdfExport(exportProperties);
}
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Export predecessor lines
The visibility of predecessor lines in the exported PDF document can be controlled using the showPredecessorLines property.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { ToolbarService, PdfExportService, SelectionService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { Gantt, Toolbar, PdfExport, Selection, PdfExportProperties, ToolbarItem, GanttComponent } from '@syncfusion/ej2-angular-gantt';
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import { SelectionSettingsModel } from '@syncfusion/ej2-angular-grids';
import { editingData } from './data';
@Component({
imports: [
GanttModule
],
providers: [ToolbarService, PdfExportService, SelectionService],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt #gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [columns]="columns" [toolbar]="toolbar"
(toolbarClick)="toolbarClick($event)" allowPdfExport='true' [treeColumnIndex]="1"></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public toolbar?: ToolbarItem[];
@ViewChild('gantt', {static: true})
public ganttChart?: GanttComponent;
columns: ({ field: string; headerText: string; textAlign: string; width: string; visible?: undefined; } | { field: string; headerText: string; width: string; visible: boolean; textAlign?: undefined; } | { field: string; headerText: string; width: string; textAlign?: undefined; visible?: undefined; })[] | undefined;
public ngOnInit(): void {
this.data = editingData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
dependency: 'Predecessor',
parentID:'ParentID',
};
this.columns = [
{ field: 'TaskID', headerText: 'Task ID', textAlign: 'Left', width: '100' },
{ field: 'TaskName', headerText: 'Task Name', width: '150' },
{ field: 'StartDate', headerText: 'StartDate', width: '150' },
{ field: 'Duration', headerText: 'Duration', width: '150' },
{ field: 'Progress', headerText: 'Progress', width: '150' }
];
this.toolbar = ['PdfExport'];
}
public toolbarClick(args: ClickEventArgs): void {
if (args.item.id === 'ganttDefault_pdfexport') {
let exportProperties: PdfExportProperties = {
showPredecessorLines: true
};
this.ganttChart!.pdfExport(exportProperties);
}
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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.
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { ToolbarService, PdfExportService, SelectionService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import { GanttComponent } from '@syncfusion/ej2-angular-gantt';
import { editingData } from './data';
@Component({
imports: [
GanttModule
],
providers: [ToolbarService, PdfExportService, SelectionService],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt #gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [columns]="columns" [toolbar]="toolbar" (beforePdfExport)="beforePdfExport()"
(toolbarClick)="toolbarClick($event)" allowPdfExport='true' [treeColumnIndex]="1"></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public toolbar?: string[];
@ViewChild('gantt', {static: true})
public ganttObj?: GanttComponent;
columns: ({ field: string; headerText: string; textAlign: string; width: string; visible?: undefined; } | { field: string; headerText: string; width: string; textAlign?: undefined; visible?: undefined; } | { field: string; headerText: string; width: string; visible: boolean; textAlign?: undefined; })[] | undefined;
public ngOnInit(): void {
this.data = editingData;
this.taskSettings = {
id: 'TaskId',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID:'ParentId',
};
this.columns = [
{ field: 'TaskId', headerText: 'Task ID', textAlign: 'Left', width: '100' },
{ field: 'TaskName', headerText: 'Task Name', width: '150' },
{ field: 'StartDate', headerText: 'StartDate', width: '150' },
{ field: 'Duration', headerText: 'Duration', width: '150', visible: false },
{ field: 'Progress', headerText: 'Progress', width: '150' }
];
this.toolbar = ['PdfExport'];
}
public toolbarClick(args: any): void {
if (args.item.id === 'ganttDefault_pdfexport') {
(this.ganttObj as any).pdfExport();
}
};
public beforePdfExport(): void {
((this.ganttObj as any).treeGrid.columns[2] as any).visible = false;
((this.ganttObj as any).treeGrid.columns[3] as any).visible = true;
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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.
import { GanttModule, GanttComponent } from '@syncfusion/ej2-angular-gantt';
import { Component, ViewChild } from '@angular/core';
import { ToolbarService, PdfExportService, SelectionService } from '@syncfusion/ej2-angular-gantt'
import { PdfColor } from '@syncfusion/ej2-pdf-export';
import { ToolbarItem } from '@syncfusion/ej2-gantt';
import { editingData } from './data';
@Component({
selector: 'app-root',
standalone: true,
imports: [GanttModule],
providers: [ToolbarService, PdfExportService, SelectionService],
template: `
<ejs-gantt
#gantt
id="ganttChart"
height="430px"
[dataSource]="taskData"
[taskFields]="taskFields"
[toolbar]="toolbar"
allowPdfExport='true'
[treeColumnIndex]="1"
(toolbarClick)="toolbarClick($event)"
(pdfQueryCellInfo)="pdfQueryCellInfo($event)"
>
</ejs-gantt>
`,
})
export class AppComponent {
public taskData?: object;
public taskFields?: object;
public toolbar?: ToolbarItem[];
public columns?: object[];
@ViewChild('gantt', {static: true})
public ganttRef?: GanttComponent;
ngOnInit(): void {
this.taskData = editingData;
this.taskFields = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
dependency: 'Predecessor',
parentID:'ParentID',
};
this.columns = [
{ field: 'TaskID' },
{ field: 'TaskName', headerText: 'Task Name', width: '250', clipMode: 'EllipsisWithTooltip' },
{ field: 'StartDate' },
{ field: 'Duration' }
];
this.toolbar = ['PdfExport'];
}
public toolbarClick(args: any): void {
if (args.item.id === 'ganttChart_pdfexport') {
this.ganttRef?.pdfExport();
}
}
public pdfQueryCellInfo(args: any): void {
if(args.column.field == 'Progress'){
if(args.value < 50) {
args.style.backgroundColor = new PdfColor(240, 128, 128);
} else {
args.style.backgroundColor = new PdfColor(165, 105, 189);
}
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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.timelineCell.backgroundColor
property.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { ToolbarService, PdfExportService, SelectionService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { PdfColor } from '@syncfusion/ej2-pdf-export';
import { Gantt, Toolbar, PdfExport, Selection, PdfQueryTimelineCellInfoEventArgs, ToolbarItem, GanttComponent } from '@syncfusion/ej2-angular-gantt';
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import { SelectionSettingsModel } from '@syncfusion/ej2-angular-grids';
import { editingData } from './data';
@Component({
imports: [
GanttModule
],
providers: [ToolbarService, PdfExportService, SelectionService],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt #gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [columns]="columns" [toolbar]="toolbar" (pdfQueryTimelineCellInfo)="pdfQueryTimelineCellInfo($event)"
(toolbarClick)="toolbarClick($event)" allowPdfExport='true' [treeColumnIndex]="1"></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public toolbar?: ToolbarItem[];
@ViewChild('gantt', {static: true})
public ganttChart?: GanttComponent;
columns: ({ field: string; headerText: string; textAlign: string; width: string; visible?: undefined; } | { field: string; headerText: string; width: string; visible: boolean; textAlign?: undefined; } | { field: string; headerText: string; width: string; textAlign?: undefined; visible?: undefined; })[] | undefined;
public ngOnInit(): void {
this.data = editingData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID:'ParentID',
};
this.columns = [
{ field: 'TaskID', headerText: 'Task ID', textAlign: 'Left', width: '100' },
{ field: 'TaskName', headerText: 'Task Name', width: '150', visible: false },
{ field: 'StartDate', headerText: 'StartDate', width: '150' },
{ field: 'Duration', headerText: 'Duration', width: '150' },
{ field: 'Progress', headerText: 'Progress', width: '150' }
];
this.toolbar = ['PdfExport'];
}
public toolbarClick(args: ClickEventArgs): void {
if (args.item.id === 'ganttDefault_pdfexport') {
this.ganttChart!.pdfExport();
}
};
public pdfQueryTimelineCellInfo(args: any): void {
args.timelineCell.backgroundColor = new PdfColor(240, 248, 255);
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { ToolbarService, PdfExportService, SelectionService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { PdfColor } from '@syncfusion/ej2-pdf-export';
import { GanttComponent, ToolbarItem } from '@syncfusion/ej2-angular-gantt';
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import { SelectionSettingsModel } from '@syncfusion/ej2-angular-grids';
import { editingData } from './data';
@Component({
imports: [
GanttModule
],
providers: [ToolbarService, PdfExportService, SelectionService],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt #gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [columns]="columns" [toolbar]="toolbar" (pdfQueryTaskbarInfo)="pdfQueryTaskbarInfo($event)"
(toolbarClick)="toolbarClick($event)" allowPdfExport='true' [treeColumnIndex]="1"></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public toolbar?: ToolbarItem[];
@ViewChild('gantt', {static: true})
public ganttChart?: GanttComponent;
columns: ({ field: string; headerText: string; textAlign: string; width: string; visible?: undefined; } | { field: string; headerText: string; width: string; visible: boolean; textAlign?: undefined; } | { field: string; headerText: string; width: string; textAlign?: undefined; visible?: undefined; })[] | undefined;
public ngOnInit(): void {
this.data = editingData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID:'ParentID',
};
this.columns = [
{ field: 'TaskID', headerText: 'Task ID', textAlign: 'Left', width: '100' },
{ field: 'TaskName', headerText: 'Task Name', width: '150', visible: false },
{ field: 'StartDate', headerText: 'StartDate', width: '150' },
{ field: 'Duration', headerText: 'Duration', width: '150' },
{ field: 'Progress', headerText: 'Progress', width: '150' }
];
this.toolbar = ['PdfExport'];
}
public toolbarClick(args: ClickEventArgs): void {
if (args.item.id === 'ganttDefault_pdfexport') {
this.ganttChart!.pdfExport();
}
};
public pdfQueryTaskbarInfo(args : any): void {
if(args.data.Progress < 50 && !args.data.hasChildRecords) {
args.taskbar.progressColor = new PdfColor(205, 92, 92);
args.taskbar.taskColor = args.taskbar.taskBorderColor = new PdfColor(240, 128, 128);
}
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { ToolbarService, PdfExportService, SelectionService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { Gantt, Toolbar, PdfExport, Selection, PdfExportProperties, PdfBorders, PdfPaddings, GanttComponent, ToolbarItem, IGanttStyle } from '@syncfusion/ej2-angular-gantt';
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import { PdfColor, PdfDashStyle, PdfFontFamily, PdfFontStyle, PdfStandardFont, PdfPen, PdfStringFormat, PdfTextAlignment, PdfVerticalAlignment} from '@syncfusion/ej2-pdf-export';
import { DayMarkersService } from '@syncfusion/ej2-angular-gantt'
import { editingData } from './data';
@Component({
imports: [GanttModule],
providers: [ToolbarService, PdfExportService, SelectionService,DayMarkersService],
standalone: true,
selector: "app-root",
template: `<ejs-gantt
#gantt
id="ganttDefault"
height="430px"
[dataSource]="data"
[taskFields]="taskSettings"
[toolbar]="toolbar"
(toolbarClick)="toolbarClick($event)"
allowPdfExport="true"
[treeColumnIndex]="1"
[eventMarkers]="eventMarkers"
[holidays] = "holidays"
></ejs-gantt>`,
encapsulation: ViewEncapsulation.None,
})
export class AppComponent {
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public toolbar?: ToolbarItem[];
public eventMarkers ?: object[];
public holidays?: object[];
@ViewChild("gantt", { static: true })
public ganttObj?: GanttComponent;
public ngOnInit(): void {
this.data = editingData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate:'EndDate',
duration: 'Duration',
dependency:'Predecessor',
progress: 'Progress',
parentID:'ParentID',
};
this.eventMarkers =[
{
day: '04/10/2019',
cssClass: 'e-custom-event-marker',
label: 'Project approval and kick-off'
}
];
this.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"
}];
this.toolbar = ["PdfExport"];
}
public toolbarClick(args: ClickEventArgs): void {
if (args.item.id === "ganttDefault_pdfexport") {
const stringFormat = new PdfStringFormat();
stringFormat.alignment = PdfTextAlignment.Center;
const vertical = new PdfStringFormat();
vertical.alignment = PdfTextAlignment.Center;
const penColor = new PdfColor(105, 105, 105);
const penWidth = 1;
const pen = new PdfPen(penColor, penWidth);
pen.dashStyle = PdfDashStyle.Dash;
const borderWidth = 1;
const borderColor = new PdfColor(192, 192, 192);
let pdfpen: PdfPen = new PdfPen(borderColor, borderWidth);
let pdfborders: PdfBorders = new PdfBorders();
pdfborders.all = pdfpen;
let exportProperties: PdfExportProperties = {
ganttStyle: {
connectorLineColor: new PdfColor(128, 0, 0),
taskbar: {
taskColor: new PdfColor(240, 128, 128),
taskBorderColor: new PdfColor(255, 0, 0),
progressColor: new PdfColor(205, 92, 92),
},
columnHeader: {
backgroundColor: new PdfColor(179, 219, 255),
},
timeline: {
backgroundColor: new PdfColor(179, 219, 255),
padding: new PdfPaddings(5, 2, 0, 0),
},
footer: {
backgroundColor: new PdfColor(205, 92, 92),
},
label: {
fontColor: new PdfColor(128, 0, 0),
},
cell: {
backgroundColor: new PdfColor(240, 248, 255),
fontColor: new PdfColor(0, 0, 0),
borderColor: new PdfColor(179, 219, 255),
},
fontFamily: 1,
eventMarker: {
label: {
backgroundColor: new PdfColor(255, 239, 213),
fontFamily: PdfFontFamily.TimesRoman,
fontColor: new PdfColor(139, 69, 19),
fontSize: 9,
format: stringFormat,
fontStyle: PdfFontStyle.Bold,
borderColor: new PdfColor(160, 82, 45),
borders: pdfborders,
},
lineStyle: pen,
},
holiday: {
fontFamily: PdfFontFamily.TimesRoman,
fontSize: 10,
fontStyle: PdfFontStyle.Bold,
borderColor: new PdfColor(211, 211, 211),
backgroundColor: new PdfColor(255, 248, 220),
fontColor: new PdfColor(105, 105, 105),
format: vertical,
borders: pdfborders,
},
},
};
this.ganttObj!.pdfExport(exportProperties);
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { ToolbarService, PdfExportService, SelectionService, EditService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { GanttComponent, ToolbarItem, SelectionSettingsModel, EditSettingsModel } from '@syncfusion/ej2-angular-gantt';
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import { PdfColor } from '@syncfusion/ej2-pdf-export';
import { ganttData } from './data';
@Component({
imports: [
GanttModule
],
providers: [ToolbarService, PdfExportService, SelectionService, EditService],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt #gantt id="ganttDefault" height="450px" [dataSource]="data" [taskFields]="taskSettings" [toolbar]="toolbar"
(toolbarClick)="toolbarClick($event)" (queryTaskbarInfo)="queryTaskbarInfo($event)" (pdfQueryTaskbarInfo)="pdfQueryTaskbarInfo($event)" [editSettings] = "editSettings" [columns]="columns" [gridLines]="gridLines" allowPdfExport='true'></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public toolbar?: ToolbarItem[];
@ViewChild('gantt', {static: true})
public ganttChart?: GanttComponent;
public editSettings?: EditSettingsModel;
public columns?: object[];
public gridLines?: string;
public ngOnInit(): void {
this.data = ganttData;
this.taskSettings = {
id: "TaskID",
name: "TaskName",
startDate: "StartDate",
endDate: "EndDate",
duration: "Duration",
progress: "Progress",
parentID:'ParentID',
segments: "Segments"
};
this.editSettings = {
allowEditing: true,
allowDeleting: true,
allowTaskbarEditing: true,
showDeleteConfirmDialog: true
},
this.toolbar = ['PdfExport'];
this.gridLines = 'Both';
this.columns = [
{ field: 'TaskID', headerText: 'Task ID' },
{ field: 'TaskName', headerText: 'Task Name' },
{ field: 'StartDate', headerText: 'StartDate' },
{ field: 'EndDate', headerText: 'End Date'}
];
}
public toolbarClick(args: ClickEventArgs): void {
if (args.item.id === 'ganttDefault_pdfexport') {
this.ganttChart!.pdfExport();
}
};
public queryTaskbarInfo(args: any) {
if (args.data.taskData.Segments) {
const segmentIndex = args.taskbarElement.dataset.segmentIndex;
if (Number(segmentIndex) === 1) {
args.taskbarBgColor = 'red';
args.taskbarBorderColor = 'black';
args.progressBarBgColor = "green";
}
}
};
public pdfQueryTaskbarInfo(args : any): void {
if (args.taskbar.taskSegmentStyles) {
args.taskbar.taskSegmentStyles[1].taskColor = new PdfColor(255, 0, 0);
args.taskbar.taskSegmentStyles[1].progressColor = new PdfColor(0, 128, 0);
args.taskbar.taskSegmentStyles[1].taskBorderColor = new PdfColor(0, 0, 0);
}
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { CommonModule } from '@angular/common';
import {
ToolbarService,
PdfExportService,
SelectionService,
} from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import {
GanttComponent,
ToolbarItem,
PdfExportProperties,
} from '@syncfusion/ej2-angular-gantt';
import { editingResources } from './data';
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
@Component({
imports: [ GanttModule,CommonModule],
providers: [ToolbarService, PdfExportService, SelectionService],
standalone: true,
selector: 'app-root',
template: `<ejs-gantt #ganttDefault id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [toolbar]="toolbar" (pdfQueryCellInfo)="pdfQueryCellInfo($event)"
(toolbarClick)="toolbarClick($event)" allowPdfExport='true' [allowResizing] = 'true' rowHeight='50' [splitterSettings]="splitterSettings" [resourceFields]="resourceFields" [resources]="resources">
<e-columns>
<e-column field='TaskID' headerText='Task ID' textAlign= 'Left' width= 100></e-column>
<e-column field='TaskName' headerText= 'Task Name' width= 150></e-column>
<e-column field= 'resources' headerText= 'Resources' width= 250>
<ng-template #template let-data>
<div *ngIf="data.ganttProperties.resourceNames">
<img src=".png" style="height:40px;width:40px"/>
</div>
</ng-template>
</e-column>
<e-column field= 'EmailId' headerText='Email ID' width= 150 ></e-column>
</e-columns></ejs-gantt>`,
encapsulation: ViewEncapsulation.None,
})
export class AppComponent {
public data?: object[];
public taskSettings?: object;
public splitterSettings?: object;
public resources?: object[];
public toolbar?: ToolbarItem[];
@ViewChild('ganttDefault', { static: true })
public ganttChart?: GanttComponent;
public resourceFields?: object;
public ngOnInit(): void {
this.data = [
{
TaskID: 1,
TaskName: 'Product concept',
StartDate: new Date('04/02/2019'),
EndDate: new Date('04/21/2019'),
EmailId: 'MartinTamer@gmail.com',
},
{
TaskID: 2,
TaskName: 'Defining the product and its usage',
StartDate: new Date('04/02/2019'),
Duration: 3,
ParentID: 1,
Progress: 30,
resources: [2],
EmailId: 'RoseFuller@gmail.com',
resourcesImage:
'/9j/4AAQSkZJRgABAQAAAQABAAD//gAfQ29tcHJlc3NlZCBieSBqcGVnLXJlY29tcHJlc3P/2wCEAAQEBAQEBAQEBAQGBgUGBggHBwcHCAwJCQkJCQwTDA4MDA4MExEUEA8QFBEeFxUVFx4iHRsdIiolJSo0MjRERFwBBAQEBAQEBAQEBAYGBQYGCAcHBwcIDAkJCQkJDBMMDgwMDgwTERQQDxAUER4XFRUXHiIdGx0iKiUlKjQyNEREXP/CABEIADcANwMBIgACEQEDEQH/xAAbAAADAAMBAQAAAAAAAAAAAAAFBwgEBgkCA//aAAgBAQAAAAC/hQFOvYjnCinKzbmZbGH5zuQtL+rjE/fO5y7I93/rpMhES5qCgxOTPErmqDaDCzVpNoBsPfbf/8QAGgEAAQUBAAAAAAAAAAAAAAAAAAECAwQFBv/aAAgBAhAAAAAoWZjmNLVM6a2Pan//xAAXAQEBAQEAAAAAAAAAAAAAAAAABAUG/9oACAEDEAAAAGjNO7PFxm1FEH//xAA3EAACAgECBAMFBgQHAAAAAAABAgMEBQAGBxESQSExMhATUVKBCBQiYWKhFiNxkTNCU2RygrH/2gAIAQEAAT8A0chavSvWwcaFUYrJdlBMSkeYjA9Z/bW5b209pY98xvncBFf57UrKrP8ACOGL1H8gCdRcfOB8txaopTojeU5p8o9Uq+OuVUv7XzrLE4DIYpvvNduY+Vif2I1Vyk0NiPH5eBYLD+EUqEmCc/BSfJv0n2ZB5MjajwlZ2RCnvbkinkViJ5CMH5n/APNdNajV5L0Q14IyflREUeJ1vDP53jTu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YREOjeT3XxjFufxhcg/ut5aMw5Ez7H6Gas7ZraHa4wzHcdVYjaOjmiSTk6f/xAAiEQACAQIGAwEAAAAAAAAAAAABAgMEEQAFEBITISJBUZH/2gAIAQMBAT8AxFltRJGsvH4H3fFTTvTPsf2LjWlBEChp1aNk8V+YzdVUwDddrH81y6t4xxkjpSLsbdYr6hamfehuoULr91//2Q==',
},
{
TaskID: 3,
TaskName: 'Defining target audience',
StartDate: new Date('04/02/2019'),
Duration: 3,
ParentID: 1,
resources: [3],
EmailId: 'MargaretBuchanan@gmail.com',
resourcesImage:
'/9j/4AAQSkZJRgABAQAAAQABAAD//gAfQ29tcHJlc3NlZCBieSBqcGVnLXJlY29tcHJlc3P/2wCEAAQEBAQEBAQEBAQGBgUGBggHBwcHCAwJCQkJCQwTDA4MDA4MExEUEA8QFBEeFxUVFx4iHRsdIiolJSo0MjRERFwBBAQEBAQEBAQEBAYGBQYGCAcHBwcIDAkJCQkJDBMMDgwMDgwTERQQDxAUER4XFRUXHiIdGx0iKiUlKjQyNEREXP/CABEIADcANwMBIgACEQEDEQH/xAAZAAACAwEAAAAAAAAAAAAAAAAEBwMFCAb/2gAIAQEAAAAA39UUCnct2dVSZMV11tS5G5fmOGS73fU8SeVXNvlpWZ6WVEOtoiTVwgBtW2poSoCztszrv//EABoBAAICAwAAAAAAAAAAAAAAAAUGAAMBAgT/2gAIAQIQAAAA1WTBChM72vCcdKyi+f/EABkBAAIDAQAAAAAAAAAAAAAAAAAGAQMFBP/aAAgBAxAAAACWjF4L3/LTR/WMcvoP/8QAHhAAAgMBAQEBAQEAAAAAAAAABAUCAwYBAAcIFBP/2gAIAQEAAQgA9NkSZZMdLpDUWdEkXoQvreHKL6PcoksbBcYZYVpdSRWvb+YTsYlVpBnDIPOJCzOPgtNuibSb2HzhkuvnfDL6jW4QvhA+cdL9xmRy7k5N8ZkKTUnOWDkMPfTuXV5uu6Fd4ku1i8006qreD+1lkIrbb/fmd1ezzr//AFe2xWkrnPs5OPEKr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nfmfZ//xAAjEQACAQQBAwUAAAAAAAAAAAABAgMABBESEAUiURMjMWKR/9oACAECAQE/AGZUVnY4UDJNTdbLSN6b6R5wO3Oasr+O6ULkb44uRtbzD6GpY4cIjKdfIrouqzKoBz3fnBAIIPwauk0Y2scezByB5rpVmbWD3FxIeY7eGJ3dEGzEknn/xAAjEQACAgEEAQUBAAAAAAAAAAABAgMEEQAFEBIiITFRYnGx/9oACAEDAQE/AFUsyqoySQANQbATEC695CMkdsY1eoS03IYeGeKx62IT911VE3m6MpPwdb/E5rvMWUAdR+kngHBBGqFvNYSysFygJPtrebot2AInzEv95kszSqiO56qAAB6Dn//Z',
},
{
TaskID: 4,
TaskName: 'Prepare product sketch and notes',
StartDate: new Date('04/02/2019'),
Duration: 2,
ParentID: 1,
Predecessor: '2',
Progress: 30,
resources: [4],
EmailId: 'FullerKing@gmail.com',
resourcesImage:
'/9j/4AAQSkZJRgABAQAAAQABAAD//gAfQ29tcHJlc3NlZCBieSBqcGVnLXJlY29tcHJlc3P/2wCEAAQEBAQEBAQEBAQGBgUGBggHBwcHCAwJCQkJCQwTDA4MDA4MExEUEA8QFBEeFxUVFx4iHRsdIiolJSo0MjRERFwBBAQEBAQEBAQEBAYGBQYGCAcHBwcIDAkJCQkJDBMMDgwMDgwTERQQDxAUER4XFRUXHiIdGx0iKiUlKjQyNEREXP/CABEIADcANwMBIgACEQEDEQH/xAAbAAACAwEBAQAAAAAAAAAAAAAFBwQGCAMCCf/aAAgBAQAAAADfwhV0x/EZ4hW5npVo+hcTlnMn4TW6ofZUBIXDSIEnOzwAaDYEyICYV79vc+aEqNLsbBM//8QAGAEAAwEBAAAAAAAAAAAAAAAAAgQFAwD/2gAIAQIQAAAABNvRaHSpjAqO9hof/8QAGQEAAgMBAAAAAAAAAAAAAAAAAgUDBAYA/9oACAEDEAAAADbLIbutRIi2OdXdagD/xAAfEAACAwEBAQADAQAAAAAAAAAEBQIDBgEHABITFBX/2gAIAQEAAQgA+/0izrLKEuj9O81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xj5UHok9WvH95gMxyfevXxFW4MWzNFIGR1+hwaaW2u5c8UJEBFkjGcMVw3iKs/Ubaxt7mOX1iZZuJLOysZMpgs37eg3ocW9fOudhjGdwg7h6P/8QAIREBAAIBBAEFAAAAAAAAAAAAAQIDAAQQETESBSJBYYH/2gAIAQIBAT8AnMhFk4a2Euph+ZXYWG2rOaX6yTxEDr5z015jMD2m0kB5yyLXKzkAVTND4RoiHart3llNdkGE48mRhGIeMToNv//EACIRAQACAQMEAwEAAAAAAAAAAAECAxEAEBIEBTFhFSEiNP/aAAgBAwEBPwCuuVs4wj5dfFTBzFUPGdXUyplxdu3/ANURQyOq6xCUs5cYdd7hwnUyRk7R5cjj510t5OqGP2kQfSa7k2T6qyUj6MB62FETVHU3U2RsrniXh96nZOaspLlV2//Z',
},
{
TaskID: 5,
TaskName: 'Concept approval',
StartDate: new Date('04/02/2019'),
Duration: 0,
Predecessor: '3,4',
resources: [5],
EmailId: 'Davoliofuller@gmail.com',
resourcesImage:
'/9j/4AAQSkZJRgABAQAAAQABAAD//gAfQ29tcHJlc3NlZCBieSBqcGVnLXJlY29tcHJlc3P/2wCEAAQEBAQEBAQEBAQGBgUGBggHBwcHCAwJCQkJCQwTDA4MDA4MExEUEA8QFBEeFxUVFx4iHRsdIiolJSo0MjRERFwBBAQEBAQEBAQEBAYGBQYGCAcHBwcIDAkJCQkJDBMMDgwMDgwTERQQDxAUER4XFRUXHiIdGx0iKiUlKjQyNEREXP/CABEIADcANwMBIgACEQEDEQH/xAAaAAACAwEBAAAAAAAAAAAAAAAHCAQFBgID/9oACAEBAAAAAH+qsdiSrczqiUBMb22cXitDeKqHJh+9YFRxtGA87Oevw2Kx1qZOdFq/gVwmsmjsTDfKu9sf/8QAGQEAAwEBAQAAAAAAAAAAAAAAAAQFBgED/9oACAECEAAAAORaDfjmqNozlhsZWP/EABkBAAIDAQAAAAAAAAAAAAAAAAAGAwQFAf/aAAgBAxAAAADu/l0535dXB6VKBDMf/8QANRAAAgIBAgQ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DFWsCdJUYq7zIxYScfkTxGvCn8S2e3ZNits39ny5LKjyWr9SURx8naVoyvRtYynNWSa1dIa/aYSTkei9ljH7UHs8QPCTa+/4C1+uIbw+CzF5XGsNsbdXhdtnI4PEClfju5SSy1qySAsRijjCKilSX8vxa8RU35ubBxbdwWBrQGy5F65+ZQNLGT0iHE8VX9etl/hN3LlpIbe5MrWq0+6Vn53OtheGe1vDvHpSwNBEk/wAyc9Xdu5JPs//EACMRAAIBAwMEAwAAAAAAAAAAAAECAwAREgQQMQUTIUEiM3L/2gAIAQIBAT8AJABJ4FSdWChmwOPANaPVJq4s15HO0/0y/k1IUKhcSUHqulKEzwSysLnzvPBJFM0CDk3Xx6NaOJooQrizHfJTAD2o8wbCS3ytv//EACMRAAEDAwQCAwAAAAAAAAAAAAECAxEABBIFECExFCJBUXH/2gAIAQMBAT8AAJIA7JimNELsAujOORV7Zrs3i0v9B2tY8liTHuO6t7Vcyk4qUJyNa8BnC3cnEKCRA7ESd9OvG3rYXD6uQnE8/IrUXkv3K1oVkn73BcDpSHlhCuSifUnf/9k=',
},
{
TaskID: 6,
TaskName: 'Market research',
StartDate: new Date('04/02/2019'),
EndDate: new Date('04/21/2019'),
EmailId: 'Vanjack@gmail.com',
},
{
TaskID: 7,
TaskName: 'Demand analysis',
StartDate: new Date('04/04/2019'),
EndDate: new Date('04/21/2019'),
EmailId: 'RoseFuller@gmail.com',
},
{
TaskID: 8,
TaskName: 'Customer strength',
StartDate: new Date('04/04/2019'),
Duration: 4,
Predecessor: '5',
Progress: 30,
resources: [7],
EmailId: 'Fullerbuchanan@gmail.com',
resourcesImage:
'/9j/4AAQSkZJRgABAQAAAQABAAD//gAfQ29tcHJlc3NlZCBieSBqcGVnLXJlY29tcHJlc3P/2wCEAAQEBAQEBAQEBAQGBgUGBggHBwcHCAwJCQkJCQwTDA4MDA4MExEUEA8QFBEeFxUVFx4iHRsdIiolJSo0MjRERFwBBAQEBAQEBAQEBAYGBQYGCAcHBwcIDAkJCQkJ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vRbY2ZQxUUaDs1DSunk8rgF21vdCNu2FHexli+56tYI+zm/iW7mqWHKA+sMx60P8kamj7WGaMnkHUr/ALGs5kbuJ2xkaMkDA17TVJH8kVonAKuf2gj11j8hkMpiqlubHSU4Y4lQ8uouXA5c1Ze4aFu1Yov7eJEkUMCsg6SeXkdbf6IsFiliUL1VYj3D4oNZKFMhkaGJPNo0V7Vnl6KAUQfcnWVq2Ip4Mxj4y9mBSksQ854CeZUfMPNdVrte/VSzVk643+xBHmCPQjXGixgsPuPEVhN2VjORTpbjA8DCLpEc31gnlra/tQq169mSvJFCp7Hkh6vCeRKk+Q1JZTK5T9KpsJrTP1OqnmEjT1b4AE6xOQgweMhx83azyIAkCjxPMxPPpX7n7DWMpzVkmtXSGv2mEk5HkvosY+VB+VvDv28l7FWjUuP7/hDRS/Wnx/uNcSeHlzcYpWc7EDLUNns545AwmE/SSPRkKlfDqngt/i3Xw0WYWtiWcq11wkk0UfyovIsx1szaX6NjWqYHHgCWTnNkrsoeawR++QLzJPwXuUaxuGgx7e1TObF4ry7Vx7oPogHuj8v/xAAjEQACAgEDAwUAAAAAAAAAAAABAwIRABAhMQQFYRIyQVFi/9oACAECAQE/AOMHUpn7WA4tsWi4SBHjQ7g4ulxkv1A2Tx5zthK5MT+r1mmKmygRyLGdCqQLZgGtt9Wwi1sJz5oDL+BsPoaf/8QAIhEAAgEDAwUBAAAAAAAAAAAAAQMCAAQREBIhBRMiMWFi/9oACAEDAQE/AIgyIiPZo2D1kdxUqeiSCBIEfDok7WrP6FXEJMYGY2j7XVYhioOzyAI6puZXNpBwwDE811RsT2oGXkSTt+a2l25FuxK8beSMjkZo5lIzkSZH2T70/9k=',
},
];
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
resourceInfo: 'resources',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID:'ParentID',
};
this.toolbar = ['PdfExport'];
this.splitterSettings = {
columnIndex: 4,
};
this.resourceFields = {
id: 'resourceId',
name: 'resourceName',
};
this.resources = editingResources;
}
public toolbarClick(args: ClickEventArgs): void {
if (args.item.id === 'ganttDefault_pdfexport') {
let exportProperties: PdfExportProperties = {
fileName: 'new.pdf',
};
this.ganttChart!.pdfExport(exportProperties);
}
}
public pdfQueryCellInfo(args: any): void {
if (args.column.headerText === 'Resources') {
{
args.image = {
height: 40,
width: 40,
base64: (args as any).data.taskData.resourcesImage,
};
}
}
if (args.column.headerText === 'Email ID') {
args.hyperLink = {
target: 'mailto:' + (args as any).data.taskData.EmailId,
displayText: (args as any).data.taskData.EmailId,
};
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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 templates, 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.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import {
ToolbarService,
PdfExportService,
SelectionService,
} from '@syncfusion/ej2-angular-gantt'
import './app.component.css';
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import {
GanttComponent,
ToolbarItem,
PdfExportProperties
} from '@syncfusion/ej2-angular-gantt';
import { editingResources, base64Data } from './data';
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
@Component({
imports: [ GanttModule],
providers: [ToolbarService, PdfExportService, SelectionService],
standalone: true,
selector: 'app-root',
template: `<ejs-gantt #ganttDefault id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [columns]="columns" [toolbar]="toolbar" [rowHeight]="45" [taskbarHeight]="35" (pdfQueryTaskbarInfo)="pdfQueryTaskbarInfo($event)"
(toolbarClick)="toolbarClick($event)" allowPdfExport='true' [allowResizing] = 'true' [splitterSettings]="splitterSettings" [resourceFields]="resourceFields" [resources]="resources"
>
<ng-template #taskbarTemplate let-data>
<div class="e-gantt-child-taskbar-inner-div e-gantt-child-taskbar" style="position:absolute; height: 100%">
<img [src]="'./' + data.ganttProperties.resourceInfo[0].resourceId + '.png'" style="height: 40px; width: 40px;">
<span class="e-span"></span>
</div>
</ng-template>
<ng-template #parentTemplate let-data>
<div class="e-gantt-parent-taskbar-inner-div e-gantt-parent-taskbar" style="position:absolute; height: 100%">
<span class="e-span"></span>
</div>
</ng-template>
<ng-template #milestoneTemplate let-data>
<div>
<div class="e-gantt-milestone" style="width:26px;height:26px;position:absolute;transform: rotate(45deg);left:1px;">
<div class="image" style="position:absolute; left: 8px ; top: 4px">
<img class="moments" src=.png height="25px" width="25px" />
</div>
</div>
</div>
</ng-template>
</ejs-gantt>`,
encapsulation: ViewEncapsulation.None,
})
export class AppComponent {
public data?: object[];
public taskSettings?: object;
public splitterSettings?: object;
public resources?: object[];
public rowHeight?: number;
public toolbar?: ToolbarItem[];
@ViewChild('ganttDefault', { static: true })
public ganttChart?: GanttComponent;
columns: ({ field: string; headerText: string; textAlign: string; width: string; visible?: undefined; } | { field: string; headerText: string; width: string; visible: boolean; textAlign?: undefined; } | { field: string; headerText: string; width: string; textAlign?: undefined; visible?: undefined; })[] | undefined;
public resourceFields?: object;
public ngOnInit(): void {
this.data = base64Data,
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
resourceInfo: 'Resources',
startDate: 'StartDate',
duration: 'Duration',
parentID:'ParentID',
};
this.toolbar = ['PdfExport'];
this.columns = [
{ field: 'TaskID', headerText: 'Task ID', textAlign: 'Left', width: '100' },
{ field: 'TaskName', headerText: 'Task Name', width: '150'},
];
this.splitterSettings = {
columnIndex: 1,
};
this.resourceFields = {
id: 'ResourceId',
name: 'ResourceName',
};
this.resources = editingResources;
}
public toolbarClick(args: ClickEventArgs): void {
if (args.item.id === 'ganttDefault_pdfexport') {
let exportProperties: PdfExportProperties = {
fileName: 'new.pdf',
};
this.ganttChart!.pdfExport(exportProperties);
}
}
public pdfQueryTaskbarInfo(args: any): void {
if (!args.data.hasChildRecords) {
if (args.data.ganttProperties.resourceNames) {
args.taskbarTemplate.image = [{
width: 20, base64: (args as any).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 as any).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 as any).data.taskData.resourcesImage, height: 20,
}]
}
args.taskbarTemplate.value = args.data.TaskName
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import {
ToolbarService,
PdfExportService,
SelectionService,
} from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import {
GanttComponent,
ToolbarItem,
PdfExportProperties,
} from '@syncfusion/ej2-angular-gantt';
import { base64Data, editingResources } from './data';
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
@Component({
imports: [ GanttModule],
providers: [ToolbarService, PdfExportService, SelectionService],
standalone: true,
selector: 'app-root',
template: `<ejs-gantt #ganttDefault id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [toolbar]="toolbar" [labelSettings]="labelSettings" (pdfQueryTaskbarInfo)="pdfQueryTaskbarInfo($event)"
(toolbarClick)="toolbarClick($event)" allowPdfExport='true' [allowResizing] = 'true' [projectStartDate]="projectStartDate" [projectEndDate]="projectEndDate" [splitterSettings]="splitterSettings" [resourceFields]="resourceFields" [resources]="resources">
<e-columns>
<e-column field='TaskID' headerText='Task ID' textAlign='Left'></e-column>
<e-column field='TaskName' headerText='Task Name' width='250'></e-column>
</e-columns>
<ng-template #labelSettingsLeftLabel let-data>
<span> [ % ]</span>
</ng-template>
<ng-template #labelSettingsRightLabel let-data>
<div
style="display:inline-flex"
innerHtml=""></div>
</ng-template>
</ejs-gantt>`,
styleUrls: ['app.component.css'],
encapsulation: ViewEncapsulation.None,
})
export class AppComponent {
public data?: object[];
public taskSettings?: object;
public splitterSettings?: object;
public labelSettings?: object;
public resources?: object[];
public projectStartDate?: Date;
public projectEndDate?: Date;
public toolbar?: ToolbarItem[];
public customFunction(data: any): string {
var container = document.createElement('div');
if (data.ganttProperties.resourceNames) {
var resources = data.Resources.split(',');
for (var i = 0; i < resources.length; i++) {
var subContainer = document.createElement('div');
var img = document.createElement('img');
var span = document.createElement('span');
span.className = 'labelClass';
span.innerHTML = resources[i];
img.src = 'https://ej2.syncfusion.com/angular/demos/assets/gantt/images/' +
resources[i] +'.png';
img.height = 30;
img.width = 30;
subContainer.append(img);
subContainer.append(span);
container.append(subContainer);
}
}
return container.innerHTML;
}
@ViewChild('ganttDefault', { static: true })
public ganttChart?: GanttComponent;
public resourceFields?: object;
public ngOnInit(): void {
this.data = base64Data;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
resourceInfo: 'Resources',
progress : 'Progress',
startDate: 'StartDate',
duration: 'Duration',
parentID:'ParentID',
};
this.toolbar = ['PdfExport'];
this.splitterSettings = {
columnIndex: 1,
};
this.resourceFields = {
id: 'ResourceId',
name: 'ResourceName',
};
this.labelSettings = {
taskLabel: '${Progress}%',
};
this.resources = editingResources;
this.projectStartDate= new Date('03/24/2019');
this.projectEndDate= new Date('04/30/2019');
}
public toolbarClick(args: ClickEventArgs): void {
if (args.item.id === 'ganttDefault_pdfexport') {
let exportProperties: PdfExportProperties = {
fileName: 'new.pdf',
};
this.ganttChart!.pdfExport(exportProperties);
}
}
public pdfQueryTaskbarInfo(args: any): void {
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 as any).data.taskData.resourcesImage, width: 20, height: 20
}]
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import {
ToolbarService,
PdfExportService,
SelectionService,
} from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import {
GanttComponent,
ToolbarItem,
PdfExportProperties
} from '@syncfusion/ej2-angular-gantt';
import { editingResources,base64Data } from './data';
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
@Component({
imports: [ GanttModule],
providers: [ToolbarService, PdfExportService, SelectionService],
standalone: true,
selector: 'app-root',
template: `<ejs-gantt #ganttDefault id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [toolbar]="toolbar" [labelSettings]="labelSettings" (pdfColumnHeaderQueryCellInfo)="pdfColumnHeaderQueryCellInfo($event)"
(toolbarClick)="toolbarClick($event)" allowPdfExport='true' [allowResizing] = 'true' [projectStartDate]="projectStartDate" [projectEndDate]="projectEndDate" [splitterSettings]="splitterSettings" [resourceFields]="resourceFields" [resources]="resources">
<e-columns>
<e-column field='TaskName' width='250'>
<ng-template #headerTemplate>
<img
src="https://ej2.syncfusion.com/angular/demos/assets/gantt/images/Task name.png"
width="20"
height="20"
/> Task Name
</ng-template>
</e-column>
<e-column field='StartDate'>
<ng-template #headerTemplate>
< <img src="https://ej2.syncfusion.com/angular/demos/assets/gantt/images/Start date.png" width="20" height="20" /> Start Date
</ng-template>
</e-column>
</e-columns>
</ejs-gantt>`,
styleUrls: ['app.component.css'],
encapsulation: ViewEncapsulation.None,
})
export class AppComponent {
public data?: object[];
public taskSettings?: object;
public splitterSettings?: object;
public labelSettings?: object;
public resources?: object[];
public i: number = 0;
public projectStartDate?: Date;
public projectEndDate?: Date;
public toolbar?: ToolbarItem[];
@ViewChild('ganttDefault', { static: true })
public ganttChart?: GanttComponent;
public resourceFields?: object;
public ngOnInit(): void {
this.data = base64Data;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
resourceInfo: 'Resources',
progress : 'Progress',
startDate: 'StartDate',
duration: 'Duration',
parentID:'ParentID',
};
this.toolbar = ['PdfExport'];
this.splitterSettings = {
columnIndex: 1,
};
this.resourceFields = {
id: 'ResourceId',
name: 'ResourceName',
};
this.labelSettings = {
taskLabel: '${Progress}%',
};
this.resources = editingResources;
this.projectStartDate= new Date('03/24/2019');
this.projectEndDate= new Date('04/30/2019');
}
public toolbarClick(args: ClickEventArgs): void {
if (args.item.id === 'ganttDefault_pdfexport') {
let exportProperties: PdfExportProperties = {
fileName: 'new.pdf',
};
this.ganttChart!.pdfExport(exportProperties);
}
}
public pdfColumnHeaderQueryCellInfo(args: any): void {
let base64Array: Object[] = [
{ 'TaskName': '/9j/4AAQSkZJRgABAQIAHAAcAAD/4QBiRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAMAAAITAA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IhXJhBQ42OBrNFOwEEO5e/cbIUnSAxqBSrEbTKUZ6oxh4hPOXGt1ikkS4uhEGm6MDqHyrK5dPPqEINgNcoqANrhskLWameB0/jWL2uPPWIuYaV6PLO68Jm5CB8SvCy58+qA62nYlreOqN/INmGiCT5cpetjBnmEvcV00w2XUIAio0ndKem6L2Jq5GN2ykQEMixQEygaYBcN3KH5Y7PTxThLlL0cYMjQlliummJS6vAFlHc7qz03WewxXI+s2TiABkRKIlTDTELjvBg/MDZ6eF+WIHT+C4vaHci4i5hqprczb1xabkI5w20LNkyaQBo6lz3v5aQW8R2aYz1VOkrq9rP1Sfx3gX1P9rJvPof8PP8Ar92zDQxLHQ71NzbzJ+EHBkuAfV/X5Gefw968t8+Z7P6fZs4dUz9DvU3KXLf4QcGV4/8AV/X5HmTz968tz+X7P6/fs4dM9K+krq9ox0t/yLjv1P8Aaz7t67/fw/t9uzTH/9k=' },
]
while (this.i < base64Array.length) {
const key = Object.keys(base64Array[this.i])[0];
const value = (base64Array[this.i] as any)[key];;
if (key === args.column.field) {
args.headerTemplate.image = [{
base64: value, width: 20, height: 20
}];
args.headerTemplate.value = args.column.field;
break;
}
this.i++;
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));