Skip to content

Commit 179f1d3

Browse files
Merge pull request #4888 from syncfusion-content/908232-pdf-export
908232: Added PDF UG
2 parents 6b918ed + 026c885 commit 179f1d3

File tree

8 files changed

+912
-46
lines changed

8 files changed

+912
-46
lines changed

blazor/gantt-chart/events.md

Lines changed: 453 additions & 0 deletions
Large diffs are not rendered by default.
63.1 KB
Loading
39 KB
Loading
54.9 KB
Loading
71.3 KB
Loading
68.2 KB
Loading

blazor/gantt-chart/pdf-export.md

Lines changed: 371 additions & 43 deletions
Large diffs are not rendered by default.

blazor/gantt-chart/template-pdf-export.md

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ documentation: ug
1010

1111
# Exporting PDF with templates
1212

13-
The Gantt chart export functionality allows you to export column and header templates to a PDF document. The template contains images, customized text, and customized cells within the header and columns.
13+
The Gantt chart export functionality allows you to export both column and header templates to a PDF document. These templates can include various customizations such as images, formatted text, and custom cell styles within the header and columns.
1414

1515
## Exporting with column template
1616

17-
The PDF export functionality allows for advanced customization of Gantt columns, including the inclusion of images, background colors, and custom text. This can be achieved using the [PdfQueryCellInfo](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Gantt.GanttEvents-1.html#Syncfusion_Blazor_Gantt_GanttEvents_1_PdfQueryCellInfo) event. By handling this event, you can define how specific cells in the Gantt chart is rendered in the exported PDF.
17+
The PDF export functionality allows for advanced customization of Gantt chart columns, including the inclusion of images, background colors, and custom text. This can be achieved using the [PdfQueryCellInfo](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Gantt.GanttEvents-1.html#Syncfusion_Blazor_Gantt_GanttEvents_1_PdfQueryCellInfo) event. By handling this event, you can define how individual cells in the Gantt chart are rendered in the exported PDF.
1818

19-
The following sample code demonstrates how to use the `PdfQueryCellInfo` event to export Gantt columns with custom text and different cell background colors,
19+
The following code snippet demonstrates how to use the `PdfQueryCellInfo` event to export Gantt columns with custom text and different cell background colors,
2020

2121
```cshtml
2222
@using Syncfusion.Blazor.Gantt
@@ -109,3 +109,88 @@ The following sample code demonstrates how to use the `PdfQueryCellInfo` event t
109109
}
110110
}
111111
```
112+
113+
## Exporting with column header template
114+
115+
The PDF export functionality allows for customization of Gantt chart columns header, including the inclusion of images, background colors, and custom text. This can be achieved using the [PdfColumnHeaderQueryCellInfo](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Gantt.GanttEvents-1.html#Syncfusion_Blazor_Gantt_GanttEvents_1_PdfColumnHeaderQueryCellInfo) event. By handling this event, you can define how each column header in the Gantt chart is rendered in the exported PDF.
116+
117+
The following code snippet demonstrates how to use the `PdfColumnHeaderQueryCellInfo` event to export Gantt columns header with custom text and image on the task name column header,
118+
119+
``` cshtml
120+
@using Syncfusion.Blazor.Gantt
121+
@using Syncfusion.Blazor.Grids
122+
@using Syncfusion.Blazor.Navigations
123+
@using Syncfusion.PdfExport
124+
@using System.Net
125+
126+
<SfGantt @ref="Gantt" ID="GanttExport" DataSource="@TaskCollection" Height="450px" Width="900px" AllowPdfExport="true" Toolbar="toolbarItem">
127+
<GanttTaskFields Id="TaskId" Name="TaskName" StartDate="StartDate" EndDate="EndDate" Dependency="Predecessor"
128+
Duration="Duration" Progress="Progress" ParentID="ParentId">
129+
</GanttTaskFields>
130+
<GanttColumns>
131+
<GanttColumn Field="TaskId" HeaderText="Task Id" Width="100" HeaderTextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></GanttColumn>
132+
<GanttColumn Field="TaskName" HeaderText="Task Name"></GanttColumn>
133+
<GanttColumn Field="StartDate" HeaderText="Start Date" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></GanttColumn>
134+
<GanttColumn Field="EndDate" HeaderText="End Date"></GanttColumn>
135+
<GanttColumn Field="Duration" HeaderText="Duration"></GanttColumn>
136+
<GanttColumn Field="Predecessor" HeaderText="Dependency"></GanttColumn>
137+
</GanttColumns>
138+
<GanttEvents OnToolbarClick="ToolbarClickHandler" PdfColumnHeaderQueryCellInfo="PdfHeaderQueryCellInfoHandler" TValue="TaskData"></GanttEvents>
139+
</SfGantt>
140+
141+
@code {
142+
private List<TaskData> TaskCollection { get; set; }
143+
private SfGantt<TaskData> Gantt;
144+
private List<object> toolbarItem = new List<Object>() { new ToolbarItem() { Text = "PDF Export", TooltipText = "PDF Export", Id = "PdfExport", PrefixIcon = "e-pdfexport" } };
145+
private static WebClient webClient = new WebClient();
146+
private static byte[] imageBytes = webClient.DownloadData("https://cdn.syncfusion.com/content/images/landing-page/yes.png");
147+
private static MemoryStream imageStream = new MemoryStream(imageBytes);
148+
public static PdfImage image = PdfImage.FromStream(imageStream);
149+
protected override void OnInitialized()
150+
{
151+
this.TaskCollection = GetTaskCollection();
152+
}
153+
public async void ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
154+
{
155+
if (args.Item.Id == "PdfExport")
156+
{
157+
await Gantt.ExportToPdfAsync();
158+
}
159+
}
160+
public void PdfHeaderQueryCellInfoHandler(Syncfusion.Blazor.Gantt.PdfHeaderQueryCellInfoEventArgs args)
161+
{
162+
if (args.Column.Field == "TaskName")
163+
{
164+
args.Cell.Value = "Updated Value";
165+
args.Cell.CellStyle = new PdfElementStyle() { Image = image};
166+
}
167+
}
168+
public class TaskData
169+
{
170+
public int TaskId { get; set; }
171+
public string TaskName { get; set; }
172+
public DateTime StartDate { get; set; }
173+
public DateTime? EndDate { get; set; }
174+
public string Duration { get; set; }
175+
public int Progress { get; set; }
176+
public int? ParentId { get; set; }
177+
public string Predecessor { get; set; }
178+
}
179+
180+
public static List<TaskData> GetTaskCollection()
181+
{
182+
List<TaskData> Tasks = new List<TaskData>()
183+
{
184+
new TaskData() { TaskId = 1, TaskName = "Project initiation", StartDate = new DateTime(2022, 04, 05), EndDate = new DateTime(2022, 04, 21), },
185+
new TaskData() { TaskId = 2, TaskName = "Identify Site location", StartDate = new DateTime(2022, 04, 05), Duration = "0", Progress = 30, ParentId = 1 },
186+
new TaskData() { TaskId = 3, TaskName = "Perform soil test", StartDate = new DateTime(2022, 04, 05), Duration = "4", Progress = 40, ParentId = 1, Predecessor = "2" },
187+
new TaskData() { TaskId = 4, TaskName = "Soil test approval", StartDate = new DateTime(2022, 04, 05), Duration = "0", Progress = 30, ParentId = 1 , Predecessor = "3" },
188+
new TaskData() { TaskId = 5, TaskName = "Project estimation", StartDate = new DateTime(2022, 04, 06), EndDate = new DateTime(2022, 04, 21), },
189+
new TaskData() { TaskId = 6, TaskName = "Develop floor plan for estimation", StartDate = new DateTime(2022, 04, 06), Duration = "3", Progress = 30, ParentId = 5 },
190+
new TaskData() { TaskId = 7, TaskName = "List materials", StartDate = new DateTime(2022, 04, 06), Duration = "3", Progress = 40, ParentId = 5 },
191+
new TaskData() { TaskId = 8, TaskName = "Estimation approval", StartDate = new DateTime(2022, 04, 06), Duration = "0", Progress = 30, ParentId = 5 }
192+
};
193+
return Tasks;
194+
}
195+
}
196+
```

0 commit comments

Comments
 (0)