How can I help you?
PDF Export in Vue Gantt Chart component
3 Feb 202624 minutes to read
PDF export allows exporting Gantt data to a PDF document. You need to use the https://ej2.syncfusion.com/vue/documentation/api/gantt#pdfexport method for exporting. To enable PDF export in the Gantt, set allowPdfExport to true.
To get a configured Gantt chart for exporting, you can follow the steps outlined in the video linked below:
To export data to a PDF document, inject the PdfExport module into the Gantt.
Note: Currently, we do not have support for exporting manually scheduled tasks.
<template>
<div>
<ejs-gantt ref='gantt' id="GanttContainer" :dataSource="data" :taskFields="taskFields" :toolbar="toolbar" :toolbarClick="toolbarClick" :allowPdfExport='true' :height="height"></ejs-gantt>
</div>
</template>
<script setup>
import { provide, ref } from "vue";
import { GanttComponent as EjsGantt, Toolbar, PdfExport, Selection } from "@syncfusion/ej2-vue-gantt";
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import {editingData } from './data-source.js';
const gantt = ref(null);
const data = editingData;
const height = '450px';
const taskFields = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
const toolbar = ['PdfExport'];
const toolbarClick = (args) => {
if (args.item.id === 'GanttContainer_pdfexport') {
var exportProperties = {
fileName:"new.pdf"
};
var ganttChart = gantt.value.ej2Instances;
ganttChart.pdfExport(exportProperties);
}
};
provide('gantt', [Toolbar, PdfExport]);
</script><template>
<div>
<ejs-gantt ref='gantt' id="GanttContainer" :dataSource="data" :taskFields="taskFields" :toolbar="toolbar" :toolbarClick="toolbarClick" :allowPdfExport='true' :height="height"></ejs-gantt>
</div>
</template>
<script>
import { GanttComponent, Toolbar, PdfExport, Selection } from "@syncfusion/ej2-vue-gantt";
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import {editingData } from './data-source.js';
export default {
name: "App",
components: {
"ejs-gantt":GanttComponent
},
data: function() {
return{
data:editingData,
height:'450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
toolbar: ['PdfExport'],
toolbarClick: (args) => {
if (args.item.id === 'GanttContainer_pdfexport') {
var ganttChart = document.getElementById('GanttContainer').ej2_instances[0];
ganttChart.pdfExport();
}
},
};
},
provide: {
gantt: [Toolbar, PdfExport]
}
};
</script>Indicators in PDF exporting
The PDF export functionality allows users to export Gantt charts enriched with dynamic indicators and accompanying images. These indicators, represented by images, can be defined using the ../api/gantt/iIndicator#base64 encoding value in the data object of the data source. This data object field should be mapped to the indicator property of the task fields.
<template>
<div>
<ejs-gantt ref='gantt' id="GanttContainer" :dataSource="data" :taskFields="taskFields" :toolbar="toolbar" :toolbarClick="toolbarClick" :allowPdfExport='true' :height="height"></ejs-gantt>
</div>
</template>
<script setup>
import { provide, ref } from "vue";
import { GanttComponent as EjsGantt, Toolbar, PdfExport, Selection } from "@syncfusion/ej2-vue-gantt";
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import {editingData } from './data-source.js';
const gantt = ref(null);
const data = editingData;
const height = '450px';
const taskFields = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
const toolbar = ['PdfExport'];
const toolbarClick = (args) => {
if (args.item.id === 'GanttContainer_pdfexport') {
var exportProperties = {
fileName:"new.pdf"
};
var ganttChart = gantt.value.ej2Instances;
ganttChart.pdfExport(exportProperties);
}
};
provide('gantt', [Toolbar, PdfExport]);
</script><template>
<div>
<ejs-gantt ref='gantt' id="GanttContainer" :dataSource="data" :taskFields="taskFields" :toolbar="toolbar" :toolbarClick="toolbarClick" :allowPdfExport='true' :height="height"></ejs-gantt>
</div>
</template>
<script>
import { GanttComponent, Toolbar, PdfExport, Selection } from "@syncfusion/ej2-vue-gantt";
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import {editingData } from './data-source.js';
export default {
name: "App",
components: {
"ejs-gantt":GanttComponent
},
data: function() {
return{
data:editingData,
height:'450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks',
indicators: 'Indicators'
},
toolbar: ['PdfExport'],
toolbarClick: (args) => {
if (args.item.id === 'GanttContainer_pdfexport') {
var ganttChart = document.getElementById('GanttContainer').ej2_instances[0];
ganttChart.pdfExport();
}
},
};
},
provide: {
gantt: [Toolbar, PdfExport]
}
};
</script>Exporting Gantt data as a blob object
In Gantt, you can export the Gantt chart data as a blob object, which allows you to preview or modify the data before exporting it.
To export the Gantt chart data as a blob object, follow these steps:
Step 1: Set the fourth argument of pdfExport as true.
Step 2: Then, pdfExpComplete will return the blob object.
<template>
<div>
<ejs-gantt ref='gantt' id="GanttContainer" :dataSource="data" :allowExcelExport='true' :excelExportComplete='excelExpComplete' :pdfExportComplete='pdfExportComplete' :taskFields="taskFields" :toolbar="toolbar" :toolbarClick="toolbarClick" :allowPdfExport='true' :height="height"></ejs-gantt>
</div>
</template>
<script setup>
import { provide, ref } from "vue";
import { GanttComponent as EjsGantt, Toolbar, PdfExport, Selection,ExcelExport } from "@syncfusion/ej2-vue-gantt";
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import { projectNewData } from './data-source.js';
const gantt = ref(null);
const data = projectNewData;
const height = '450px';
const taskFields = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
const toolbar = ['PdfExport','ExcelExport'];
const toolbarClick = (args) => {
var ganttChart = gantt.value.ej2Instances;
if (args.item.id === 'GanttContainer_pdfexport') {
ganttChart.pdfExport(null,null,null,true);
}
if (args.item.id === 'GanttContainer_excelexport') {
ganttChart.ganttObj.excelExport(excelExportProperties);
}
};
const excelExpComplete = (args) => {
//This event will be triggered when excel exporting.
args.promise.then((e) => {
//In this `then` function, we can get blob data through the arguments after promise resolved.
exportBlob(e.blobData);
});
};
const pdfExportComplete = (args) => {
//This event will be triggered when pdf exporting.
args.promise.then((e) => {
//In this `then` function, we can get blob data through the arguments after promise resolved.
exportBlob(e.blobData);
});
};
const exportBlob = (blob) => {
let a = document.createElement('a');
document.body.appendChild(a);
a.style.display = 'none';
let url = window.URL.createObjectURL(blob);
a.href = url;
a.download = 'Export';
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
};
provide('gantt', [Toolbar, PdfExport,Selection,ExcelExport]);
</script><template>
<div>
<ejs-gantt ref='gantt' id="GanttContainer" :dataSource="data" :allowExcelExport='true' :excelExportComplete='excelExpComplete' :pdfExportComplete='pdfExportComplete' :taskFields="taskFields" :toolbar="toolbar" :toolbarClick="toolbarClick" :allowPdfExport='true' :height="height"></ejs-gantt>
</div>
</template>
<script>
import { GanttComponent, Toolbar, PdfExport, Selection,ExcelExport } from "@syncfusion/ej2-vue-gantt";
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import { projectNewData } from './data-source.js';
export default {
name: "App",
components: {
"ejs-gantt":GanttComponent
},
data: function() {
return{
data: projectNewData,
height:'450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
toolbar: ['PdfExport','ExcelExport'],
};
},
methods: {
toolbarClick: (args) => {
var ganttChart = document.getElementById('GanttContainer').ej2_instances[0];
if (args.item.id === 'GanttContainer_pdfexport') {
ganttChart.pdfExport(null,null,null,true);
}
if (args.item.id === 'GanttContainer_excelexport') {
ganttChart.ganttObj.excelExport(excelExportProperties);
}
},
excelExpComplete: function (args) {
//This event will be triggered when excel exporting.
args.promise.then((e) => {
//In this `then` function, we can get blob data through the arguments after promise resolved.
this.exportBlob(e.blobData);
});
},
pdfExportComplete: function (args) {
//This event will be triggered when pdf exporting.
args.promise.then((e) => {
//In this `then` function, we can get blob data through the arguments after promise resolved.
this.exportBlob(e.blobData);
});
},
exportBlob: function (blob) {
let a = document.createElement('a');
document.body.appendChild(a);
a.style.display = 'none';
let url = window.URL.createObjectURL(blob);
a.href = url;
a.download = 'Export';
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
}
},
provide: {
gantt: [Toolbar, PdfExport,Selection,ExcelExport]
}
};
</script>Single page exporting in Gantt
In Gantt, we provide support for exporting the Gantt Chart component so that each row is auto‑fitted to the PDF document’s page width by setting isFitToWidth to true in the fitToWidthSettings of PdfExportProperties.
You can also customize the chart width and grid width in the exported file using chartWidth and gridWidth by defining them as percentage values in string format.
<template>
<div>
<ejs-gantt ref='gantt' id="GanttContainer" :dataSource="data" :taskFields="taskFields" :toolbar="toolbar" :toolbarClick="toolbarClick" :allowPdfExport='true' :height="height"></ejs-gantt>
</div>
</template>
<script setup>
import { provide, ref } from "vue";
import { GanttComponent as EjsGantt, Toolbar, PdfExport, Selection } from "@syncfusion/ej2-vue-gantt";
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import {editingData } from './data-source.js';
const gantt = ref(null);
const data = editingData;
const height = '450px';
const taskFields = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate: 'EndDate',
duration: 'Duration',
progress: 'Progress',
dependency: 'Predecessor',
child: 'subtasks',
};
const toolbar = ['PdfExport'];
const toolbarClick = (args) => {
if (args.item.id === 'GanttContainer_pdfexport') {
var exportProperties = {
fitToWidthSettings: {
isFitToWidth: true,
}
};
var ganttChart = gantt.value.ej2Instances;
ganttChart.pdfExport(exportProperties);
}
};
provide('gantt', [Toolbar, PdfExport]);
</script><template>
<div>
<ejs-gantt ref='gantt' id="GanttContainer" :dataSource="data" :taskFields="taskFields" :toolbar="toolbar" :toolbarClick="toolbarClick" :allowPdfExport='true' :height="height"></ejs-gantt>
</div>
</template>
<script>
import { GanttComponent, Toolbar, PdfExport, Selection } from "@syncfusion/ej2-vue-gantt";
import { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';
import {editingData } from './data-source.js';
export default {
name: "App",
components: {
"ejs-gantt":GanttComponent
},
data: function() {
return{
data:editingData,
height:'450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate: 'EndDate',
duration: 'Duration',
progress: 'Progress',
dependency: 'Predecessor',
child: 'subtasks',
},
toolbar: ['PdfExport'],
toolbarClick: (args) => {
if (args.item.id === 'GanttContainer_pdfexport') {
var exportProperties = {
fitToWidthSettings: {
isFitToWidth: true,
}
};
var ganttChart = document.getElementById('GanttContainer').ej2_instances[0];
ganttChart.pdfExport(exportProperties);
}
},
};
},
provide: {
gantt: [Toolbar, PdfExport]
}
};
</script>Multiple Gantt exporting in Vue Gantt Chart component
PDF export provides an option to export multiple Gantt Chart components into the same file. In the exported document, each Gantt will be placed on a new page of the same file.
<template>
<div>
<p><b>First Gantt:</b></p>
<ejs-gantt ref='gantt1' id="GanttContainer1" :dataSource="fData" :taskFields="taskFields" :toolbar="toolbar" :toolbarClick="toolbarClick" :allowPdfExport='true' :height="height1" :treeColumnIndex="1" :projectStartDate="projectStartDate" :projectEndDate="projectEndDate"></ejs-gantt>
<p><b>Second Gantt:</b></p>
<ejs-gantt ref='gantt2' id="GanttContainer2" :dataSource="sData" :taskFields="taskFields" :toolbar="toolbar" :toolbarClick="toolbarClick" :allowPdfExport='true' :height="height2" :treeColumnIndex="1"></ejs-gantt>
</div>
</template>
<script setup>
import { provide, ref } from "vue";
import { GanttComponent as EjsGantt, Toolbar, PdfExport, Selection } from "@syncfusion/ej2-vue-gantt";
import { ClickEventArgs } from '@syncfusion/ej2-navigations';
import {editingData } from './data-source.js';
const gantt1 = ref(null);
const gantt2 = ref(null);
const fData = [editingData[0]];
const sData = [editingData[1]];
const height1 = '280px';
const height2 = '250px';
const taskFields = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
const toolbar = ['PdfExport'];
const projectStartDate = new Date('03/31/2019');
const projectEndDate = new Date('04/14/2019');
const toolbarClick = (args) => {
if (args.item.id === 'GanttContainer1_pdfexport') {
var firstGantt = gantt1.value.ej2Instances;
var firstGanttExport = firstGantt.pdfExport({},true);
firstGanttExport.then((fData) => {
var secondGantt = gantt2.value.ej2Instances;
secondGantt.pdfExport({},false,fData);
});
}
};
provide('gantt', [Toolbar, PdfExport]);
</script><template>
<div>
<p><b>First Gantt:</b></p>
<ejs-gantt ref='gantt1' id="GanttContainer1" :dataSource="fData" :taskFields="taskFields" :toolbar="toolbar" :toolbarClick="toolbarClick" :allowPdfExport='true' :height="height1" :treeColumnIndex="1" :projectStartDate="projectStartDate" :projectEndDate="projectEndDate"></ejs-gantt>
<p><b>Second Gantt:</b></p>
<ejs-gantt ref='gantt2' id="GanttContainer2" :dataSource="sData" :taskFields="taskFields" :toolbar="toolbar" :toolbarClick="toolbarClick" :allowPdfExport='true' :height="height2" :treeColumnIndex="1"></ejs-gantt>
</div>
</template>
<script>
import { GanttComponent, Toolbar, PdfExport, Selection } from "@syncfusion/ej2-vue-gantt";
import { ClickEventArgs } from '@syncfusion/ej2-navigations';
import {editingData } from './data-source.js';
export default {
name: "App",
components: {
"ejs-gantt":GanttComponent
},
data: function() {
return{
fData: [editingData[0]],
sData: [editingData[1]],
height1:'280px',
height2:'250px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
toolbar: ['PdfExport'],
projectStartDate: new Date('03/31/2019'),
projectEndDate: new Date('04/14/2019'),
toolbarClick: (args) => {
if (args.item.id === 'GanttContainer1_pdfexport') {
var firstGantt = document.getElementById('GanttContainer1').ej2_instances[0];
var firstGanttExport = firstGantt.pdfExport({},true);
firstGanttExport.then((fData) => {
var secondGantt = document.getElementById('GanttContainer2').ej2_instances[0];
secondGantt.pdfExport({},false,fData);
});
}
},
};
},
provide: {
gantt: [Toolbar, PdfExport]
}
};
</script>Applying Themes in PDF Export
PDF export provides an option to apply themes to the exported PDF document. To apply a theme, define the theme in pdfExportProperties.
The available themes are:
<template>
<div>
<ejs-gantt ref='gantt' id="GanttContainer" :dataSource="data" :taskFields="taskFields" :toolbar="toolbar"
:toolbarClick="toolbarClick" :allowPdfExport='true' :height="height"></ejs-gantt>
</div>
</template>
<script setup>
import { provide, ref } from "vue";
import { GanttComponent as EjsGantt, Toolbar, PdfExport, Selection } from "@syncfusion/ej2-vue-gantt";
import { ClickEventArgs } from '@syncfusion/ej2-navigations';
import { editingData } from './data-source.js';
const gantt = ref(null);
const data = editingData;
const height = '450px';
const taskFields = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
const toolbar = ['PdfExport'];
const toolbarClick = (args) => {
if (args.item.id === 'GanttContainer_pdfexport') {
var exportProperties = {
theme:"Fabric"
};
var ganttChart = gantt.value.ej2Instances;
ganttChart.pdfExport(exportProperties);
}
};
provide('gantt', [Toolbar, PdfExport]);
</script><template>
<div>
<ejs-gantt ref='gantt' id="GanttContainer" :dataSource="data" :taskFields="taskFields" :toolbar="toolbar"
:toolbarClick="toolbarClick" :allowPdfExport='true' :height="height"></ejs-gantt>
</div>
</template>
<script>
import { GanttComponent, Toolbar, PdfExport, Selection } from "@syncfusion/ej2-vue-gantt";
import { ClickEventArgs } from '@syncfusion/ej2-navigations';
import { editingData } from './data-source.js';
export default {
name: "App",
components: {
"ejs-gantt": GanttComponent
},
data: function () {
return {
data: editingData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
toolbar: ['PdfExport'],
toolbarClick: (args) => {
if (args.item.id === 'GanttContainer_pdfexport') {
var exportProperties = {
theme: "Fabric"
};
var ganttChart = document.getElementById('GanttContainer').ej2_instances[0];
ganttChart.pdfExport(exportProperties);
}
},
};
},
provide: {
gantt: [Toolbar, PdfExport]
}
};
</script>