Skip to content

Commit 550f27e

Browse files
908232: Added PDF UG
1 parent 2db285e commit 550f27e

File tree

2 files changed

+197
-187
lines changed

2 files changed

+197
-187
lines changed

blazor/gantt-chart/pdf-export.md

Lines changed: 194 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ The following sample code demonstrates adding line in the Header section of the
295295
}
296296
```
297297

298-
### How to change the change page orientation
298+
### How to change the page orientation
299299

300300
The PDF export functionality allows you to customize the page orientation of the exported document. By setting the `PageOrientation` property in the `GanttPdfExportProperties` class, you can switch between Portrait (default) and Landscape orientations based on your requirements.
301301

@@ -360,7 +360,7 @@ The following code snippet demonstrates how to set the page orientation to Lands
360360
}
361361
```
362362

363-
### How to change the change page size
363+
### How to change the page size
364364

365365
The PDF export functionality allows you to adjust the page size of the exported document to meet your specific needs. By setting the `PageSize` property in the `GanttPdfExportProperties` class, you can select from various standard page sizes. The default page size is Letter, but other options like A4, A3, and more are available.
366366

@@ -471,7 +471,7 @@ The following code demonstrates how to export the Gantt chart to a PDF with spec
471471
</GanttTaskFields>
472472
<GanttColumns>
473473
<GanttColumn Field="TaskId" HeaderText="TaskId" Width="100" HeaderTextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></GanttColumn>
474-
<GanttColumn Field="TaskName" HeaderText="TaskName"></GanttColumn>
474+
<GanttColumn Field="TaskName" HeaderText="Task Name"></GanttColumn>
475475
<GanttColumn Field="StartDate" HeaderText="Start Date" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></GanttColumn>
476476
<GanttColumn Field="EndDate" HeaderText="End Date"></GanttColumn>
477477
<GanttColumn Field="Duration" HeaderText="Duration"></GanttColumn>
@@ -546,6 +546,14 @@ The following code demonstrates how to export hidden columns in the Gantt chart
546546
<GanttTaskFields Id="TaskId" Name="TaskName" StartDate="StartDate" EndDate="EndDate" Dependency="Predecessor"
547547
Duration="Duration" Progress="Progress" ParentID="ParentId">
548548
</GanttTaskFields>
549+
<GanttColumns>
550+
<GanttColumn Field="TaskId" HeaderText="TaskId" Width="100" HeaderTextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></GanttColumn>
551+
<GanttColumn Field="TaskName" HeaderText="Task Name" Visible="false"></GanttColumn>
552+
<GanttColumn Field="StartDate" HeaderText="Start Date" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></GanttColumn>
553+
<GanttColumn Field="EndDate" HeaderText="End Date"></GanttColumn>
554+
<GanttColumn Field="Duration" HeaderText="Duration"></GanttColumn>
555+
<GanttColumn Field="Predecessor" HeaderText="Dependency"></GanttColumn>
556+
</GanttColumns>
549557
<GanttEvents OnToolbarClick="ToolbarClickHandler" TValue="TaskData"></GanttEvents>
550558
</SfGantt>
551559
@@ -598,7 +606,7 @@ The following code demonstrates how to export hidden columns in the Gantt chart
598606
```
599607
### Customize column width in exported PDF document
600608

601-
The PDF export functionality allows you to customize which columns are included in the exported PDF, as well as adjust their widths. This can be achieved using the `Columns` property in the `GanttPdfExportProperties` class. By specifying columns and their respective widths, you can tailor the PDF export to meet your specific needs.
609+
The PDF export functionality allows you to customize columns width in the exported PDF document. This can be achieved using the `Width` property in the `GanttColumn` class. By specifying columns and their respective widths, you can tailor the PDF export to meet your specific needs.
602610

603611
The following code demonstrates how to customize the columns and set their widths in the exported PDF document,
604612

@@ -614,7 +622,7 @@ The following code demonstrates how to customize the columns and set their width
614622
</GanttTaskFields>
615623
<GanttColumns>
616624
<GanttColumn Field="TaskId" HeaderText="TaskId" Width="100" HeaderTextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></GanttColumn>
617-
<GanttColumn Field="TaskName" HeaderText="TaskName"></GanttColumn>
625+
<GanttColumn Field="TaskName" HeaderText="Task Name"></GanttColumn>
618626
<GanttColumn Field="StartDate" HeaderText="Start Date" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></GanttColumn>
619627
<GanttColumn Field="EndDate" HeaderText="End Date"></GanttColumn>
620628
<GanttColumn Field="Duration" HeaderText="Duration"></GanttColumn>
@@ -675,3 +683,184 @@ The following code demonstrates how to customize the columns and set their width
675683
}
676684
}
677685
```
686+
687+
## Customizing taskbar appearance using event
688+
689+
The PDF export functionality allows you to customize taskbar appearance to a PDF document using the [PdfQueryTaskbarInfo](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Gantt.GanttEvents-1.html#Syncfusion_Blazor_Gantt_GanttEvents_1_PdfQueryTaskbarInfo) event. This event provides the flexibility to customize and format the appearance of taskbars, including parent taskbars, individual taskbars, and milestone templates.
690+
691+
The following sample code demonstrates how to use the `PdfQueryTaskbarInfo` event to customize the appearance of taskbars in the exported PDF document,
692+
693+
``` cshtml
694+
@using Syncfusion.Blazor.Gantt
695+
@using Syncfusion.Blazor.Grids
696+
@using Syncfusion.Blazor.Navigations
697+
@using Syncfusion.PdfExport
698+
699+
<SfGantt @ref="Gantt" ID="GanttExport" DataSource="@TaskCollection" Height="450px" Width="900px" AllowPdfExport="true" Toolbar="toolbarItem">
700+
<GanttTaskFields Id="TaskId" Name="TaskName" StartDate="StartDate" EndDate="EndDate" Dependency="Predecessor"
701+
Duration="Duration" Progress="Progress" ParentID="ParentId">
702+
</GanttTaskFields>
703+
<GanttColumns>
704+
<GanttColumn Field="TaskId" HeaderText="TaskId" Width="100" HeaderTextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></GanttColumn>
705+
<GanttColumn Field="TaskName" HeaderText="Task Name"></GanttColumn>
706+
<GanttColumn Field="StartDate" HeaderText="Start Date" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></GanttColumn>
707+
<GanttColumn Field="EndDate" HeaderText="End Date"></GanttColumn>
708+
<GanttColumn Field="Duration" HeaderText="Duration"></GanttColumn>
709+
<GanttColumn Field="Predecessor" HeaderText="Dependency"></GanttColumn>
710+
</GanttColumns>
711+
<GanttEvents OnToolbarClick="ToolbarClickHandler" PdfQueryTaskbarInfo="PdfQueryTaskbarInfoHandler" TValue="TaskData"></GanttEvents>
712+
</SfGantt>
713+
714+
@code {
715+
private List<TaskData> TaskCollection { get; set; }
716+
private SfGantt<TaskData> Gantt;
717+
private List<object> toolbarItem = new List<Object>() { new ToolbarItem() { Text = "PDF Export", TooltipText = "PDF Export", Id = "PdfExport", PrefixIcon = "e-pdfexport" } };
718+
protected override void OnInitialized()
719+
{
720+
this.TaskCollection = GetTaskCollection();
721+
}
722+
public async void ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
723+
{
724+
if (args.Item.Id == "PdfExport")
725+
{
726+
await Gantt.ExportToPdfAsync();
727+
}
728+
}
729+
public void PdfQueryTaskbarInfoHandler(PdfQueryTaskbarInfoEventArgs<TaskData> args)
730+
{
731+
if (args.Data.TaskId == 3)
732+
{
733+
args.TaskbarStyle.Color = new PdfTaskbarColor();
734+
args.TaskbarStyle.Color.ChildProgressColor = new Syncfusion.PdfExport.PdfColor(103, 80, 164);
735+
args.TaskbarStyle.Color.ChildTaskbarColor = new Syncfusion.PdfExport.PdfColor(141, 124, 187);
736+
}
737+
if (args.Data.TaskId == 4)
738+
{
739+
args.TaskbarStyle.Color = new PdfTaskbarColor();
740+
args.TaskbarStyle.Color.MilestoneColor = new Syncfusion.PdfExport.PdfColor(103, 80, 164);
741+
}
742+
743+
}
744+
public class TaskData
745+
{
746+
public int TaskId { get; set; }
747+
public string TaskName { get; set; }
748+
public DateTime StartDate { get; set; }
749+
public DateTime? EndDate { get; set; }
750+
public string Duration { get; set; }
751+
public int Progress { get; set; }
752+
public int? ParentId { get; set; }
753+
public string Predecessor { get; set; }
754+
}
755+
756+
public static List<TaskData> GetTaskCollection()
757+
{
758+
List<TaskData> Tasks = new List<TaskData>()
759+
{
760+
new TaskData() { TaskId = 1, TaskName = "Project initiation", StartDate = new DateTime(2022, 04, 05), EndDate = new DateTime(2022, 04, 21), },
761+
new TaskData() { TaskId = 2, TaskName = "Identify Site location", StartDate = new DateTime(2022, 04, 05), Duration = "0", Progress = 30, ParentId = 1 },
762+
new TaskData() { TaskId = 3, TaskName = "Perform soil test", StartDate = new DateTime(2022, 04, 05), Duration = "4", Progress = 40, ParentId = 1, Predecessor = "2" },
763+
new TaskData() { TaskId = 4, TaskName = "Soil test approval", StartDate = new DateTime(2022, 04, 05), Duration = "0", Progress = 30, ParentId = 1 , Predecessor = "3" },
764+
new TaskData() { TaskId = 5, TaskName = "Project estimation", StartDate = new DateTime(2022, 04, 06), EndDate = new DateTime(2022, 04, 21), },
765+
new TaskData() { TaskId = 6, TaskName = "Develop floor plan for estimation", StartDate = new DateTime(2022, 04, 06), Duration = "3", Progress = 30, ParentId = 5 },
766+
new TaskData() { TaskId = 7, TaskName = "List materials", StartDate = new DateTime(2022, 04, 06), Duration = "3", Progress = 40, ParentId = 5 },
767+
new TaskData() { TaskId = 8, TaskName = "Estimation approval", StartDate = new DateTime(2022, 04, 06), Duration = "0", Progress = 30, ParentId = 5 }
768+
};
769+
return Tasks;
770+
}
771+
}
772+
```
773+
774+
## Customizing taskbar appearance using export property
775+
776+
The PDF export functionality allows you to customize taskbar appearance to a PDF document with customized colors using the `TaskbarColor` property in the `GanttPdfExportProperties` class. This property enables you to format various types of taskbars, including parent taskbars, child taskbars, milestones, critical paths, manual taskbars, and baselines.
777+
778+
You can use the `TaskbarColor` property to set colors for the following taskbar types:
779+
780+
* Parent Taskbar Color
781+
* Child Taskbar Color
782+
* Milestone Color
783+
* Critical Path Color
784+
* Manual Taskbar Color
785+
* Baseline Color
786+
787+
The following code demonstrates how to customize the colors of different taskbars in the exported PDF document
788+
789+
``` cshtml
790+
@using Syncfusion.Blazor.Gantt
791+
@using Syncfusion.Blazor.Grids
792+
@using Syncfusion.Blazor.Navigations
793+
@using Syncfusion.PdfExport
794+
795+
<SfGantt @ref="Gantt" ID="GanttExport" DataSource="@TaskCollection" Height="450px" Width="900px" AllowPdfExport="true" Toolbar="toolbarItem" EnableCriticalPath="true"
796+
RenderBaseline="true">
797+
<GanttTaskFields Id="TaskId" Name="TaskName" StartDate="StartDate" EndDate="EndDate" BaselineStartDate="BaselineStartDate" BaselineEndDate="BaselineEndDate"
798+
Duration="Duration" Progress="Progress" ParentID="ParentId">
799+
</GanttTaskFields>
800+
<GanttColumns>
801+
<GanttColumn Field="TaskId" HeaderText="TaskId" Width="100" HeaderTextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></GanttColumn>
802+
<GanttColumn Field="TaskName" HeaderText="Task Name"></GanttColumn>
803+
<GanttColumn Field="StartDate" HeaderText="Start Date" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></GanttColumn>
804+
<GanttColumn Field="EndDate" HeaderText="End Date"></GanttColumn>
805+
<GanttColumn Field="Duration" HeaderText="Duration"></GanttColumn>
806+
</GanttColumns>
807+
<GanttEvents OnToolbarClick="ToolbarClickHandler" TValue="TaskData"></GanttEvents>
808+
</SfGantt>
809+
810+
@code {
811+
private List<TaskData> TaskCollection { get; set; }
812+
private SfGantt<TaskData> Gantt;
813+
private List<object> toolbarItem = new List<Object>() { new ToolbarItem() { Text = "PDF Export", TooltipText = "PDF Export", Id = "PdfExport", PrefixIcon = "e-pdfexport" } };
814+
protected override void OnInitialized()
815+
{
816+
this.TaskCollection = GetTaskCollection();
817+
}
818+
public async void ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
819+
{
820+
if (args.Item.Id == "PdfExport")
821+
{
822+
GanttPdfExportProperties pdfExport = new GanttPdfExportProperties();
823+
pdfExport.Style = new PdfGanttStyle();
824+
pdfExport.Style.TaskbarColor = new PdfTaskbarColor();
825+
pdfExport.Style.TaskbarColor.ParentTaskbarColor = new PdfColor(220, 118, 51);
826+
pdfExport.Style.TaskbarColor.ParentProgressColor = new PdfColor(203, 67, 53);
827+
pdfExport.Style.TaskbarColor.ChildProgressColor = new PdfColor(35, 155, 86);
828+
pdfExport.Style.TaskbarColor.ChildTaskbarColor = new PdfColor(130, 224, 170);
829+
pdfExport.Style.TaskbarColor.CriticalPathTaskbarColor = new PdfColor(173, 121, 64);
830+
pdfExport.Style.TaskbarColor.CriticalPathProgressColor = new PdfColor(145, 76, 0);
831+
pdfExport.Style.TaskbarColor.BaselineColor = new PdfColor(179, 38, 30);
832+
pdfExport.Style.TaskbarColor.MilestoneColor = new PdfColor(141, 124, 187);
833+
await Gantt.ExportToPdfAsync(pdfExport);
834+
}
835+
}
836+
837+
public class TaskData
838+
{
839+
public int TaskId { get; set; }
840+
public string TaskName { get; set; }
841+
public DateTime? BaselineStartDate { get; set; }
842+
public DateTime? BaselineEndDate { get; set; }
843+
public DateTime StartDate { get; set; }
844+
public DateTime? EndDate { get; set; }
845+
public string Duration { get; set; }
846+
public int Progress { get; set; }
847+
public int? ParentId { get; set; }
848+
}
849+
850+
public static List<TaskData> GetTaskCollection()
851+
{
852+
List<TaskData> Tasks = new List<TaskData>()
853+
{
854+
new TaskData() { TaskId = 1, TaskName = "Project initiation", BaselineStartDate = new DateTime(2021, 04, 02), BaselineEndDate = new DateTime(2021, 04, 04), StartDate = new DateTime(2021, 04, 02), EndDate = new DateTime(2021, 04, 06) },
855+
new TaskData() { TaskId = 2, TaskName = "Identify site location", StartDate = new DateTime(2021, 04, 02), EndDate = new DateTime(2021, 04, 02), Duration = "0", BaselineStartDate = new DateTime(2021, 04, 02), BaselineEndDate = new DateTime(2021, 04, 02), Progress = 30, ParentId = 1 },
856+
new TaskData() { TaskId = 3, TaskName = "Perform soil test", StartDate = new DateTime(2021, 04, 02), Duration = "5", Progress = 40, BaselineStartDate = new DateTime(2021, 04, 02), BaselineEndDate = new DateTime(2021, 04, 06), ParentId = 1 },
857+
new TaskData() { TaskId = 4, TaskName = "Soil test approval", StartDate = new DateTime(2021, 04, 08), Duration = "0", EndDate = new DateTime(2021, 04, 08), BaselineStartDate = new DateTime(2021, 04, 08), BaselineEndDate = new DateTime(2021, 04, 08), Progress = 30, ParentId = 1 },
858+
new TaskData() { TaskId = 5, TaskName = "Project initiation", StartDate = new DateTime(2021, 04, 02), EndDate = new DateTime(2021, 04, 08) },
859+
new TaskData() { TaskId = 6, TaskName = "Identify site location", StartDate = new DateTime(2021, 04, 02), Duration = "2", Progress = 30, ParentId = 5, BaselineStartDate = new DateTime(2021, 04, 02), BaselineEndDate = new DateTime(2021, 04, 02) },
860+
new TaskData() { TaskId = 7, TaskName = "Perform soil test", StartDate = new DateTime(2021, 04, 02), Duration = "4", Progress = 40, ParentId = 5, BaselineStartDate = new DateTime(2021, 04, 02), BaselineEndDate = new DateTime(2021, 04, 03) },
861+
new TaskData() { TaskId = 8, TaskName = "Soil test approval", StartDate = new DateTime(2021, 04, 02), Duration = "5", Progress = 30, ParentId = 5, BaselineStartDate = new DateTime(2021, 04, 02), BaselineEndDate = new DateTime(2021, 04, 04) }
862+
};
863+
return Tasks;
864+
}
865+
}
866+
```

0 commit comments

Comments
 (0)