Header and Footer of PDF Exporting in Blazor Gantt Chart Component
18 Nov 201813 minutes to read
Customizing headers and footers in PDF exports of the Blazor Gantt Chart component allows adding text, lines, page numbers, and images to enhance document professionalism for projects. Use GanttPdfExportProperties with Header and Footer to define content arrays, specifying Type (e.g., Text, Line), Value, Position, Style, or Src for images with Base64 encoding.
Adding text in header and footer
The Syncfusion Blazor Gantt Chart allows you to add custom text to the header and footer sections when exporting the Gantt content to PDF.
- The header appears at the top of each exported page and is typically used to display a document title, company branding, logos, dates, or other identifying information.
- The footer appears at the bottom of each page and commonly includes page numbers, copyright notices, disclaimers, or similar supporting details.
Header and footer text can be customized using the Header and Footer properties available in GanttPdfExportProperties. To display text within the header or footer:
- Set the
Typeproperty toTextto indicate that the element displays textual content. - Use the
Valueproperty to define the text you want to show, such as titles, page labels, or metadata. - Set the
Positionproperty to specify the X and Y coordinates for the text placement inside the header or footer area.
Styling the text
The appearance of the header or footer text can be customized using the Style property. The following styling options are supported:
- DashStyle: Defines the dash pattern applied to the text element.
- FontSize: Specifies the size of the text.
-
HAlign: Determines the horizontal alignment of the text. Supported values include
Left,Center,Right, andJustify. -
VAlign: Determines the vertical alignment of the text. Supported values include
Top,Middle, andBottom. - PenColor: Sets the color of the pen used to outline the text.
- PenSize: Sets the thickness of the pen used for outlining.
- TextBrushColor: Specifies the fill color used to render the text.
- TextPenColor: Specifies the outline color applied to the text.
These style options allow full control over text color, size, alignment, and appearance. The HAlign property is especially useful for aligning text horizontally within the header or footer area, ensuring a consistent and professional layout in the exported PDF.
@using Syncfusion.Blazor.Gantt
@using Syncfusion.Blazor.Grids
<SfGantt @ref="Gantt" ID="GanttExport" DataSource="@TaskCollection" Height="450px" Width="900px" AllowPdfExport="true" Toolbar="toolbarItem">
<GanttTaskFields Id="TaskId" Name="TaskName" StartDate="StartDate" EndDate="EndDate" Dependency="Predecessor"
Duration="Duration" Progress="Progress" ParentID="ParentId">
</GanttTaskFields>
<GanttEvents OnToolbarClick="ToolbarClickHandler" TValue="TaskData"></GanttEvents>
</SfGantt>
@code {
public List<TaskData>? TaskCollection { get; set; }
public SfGantt<TaskData>? Gantt;
private List<object> toolbarItem = new List<Object>() { new Syncfusion.Blazor.Navigations.ToolbarItem() { Text = "PDF Export", TooltipText = "PDF Export", Id = "PdfExport", PrefixIcon = "e-pdfexport" } };
public List<PdfHeaderFooterContent> HeaderContent = new List<PdfHeaderFooterContent>
{
new PdfHeaderFooterContent() { Type = ContentType.Text, Value = "Gantt Chart PDF Export Header", Position = new PdfPosition() { X = 0, Y = 50 }, Style = new PdfContentStyle() { TextBrushColor = "#000000", FontSize = 13, HAlign = PdfHorizontalAlign.Center } }
};
public List<PdfHeaderFooterContent> FooterContent = new List<PdfHeaderFooterContent>
{
new PdfHeaderFooterContent() { Type = ContentType.Text, Value = "Gantt Chart PDF Export Footer", Position = new PdfPosition() { X = 0, Y = 350 }, Style = new PdfContentStyle() { TextBrushColor = "#000000", FontSize = 13, HAlign = PdfHorizontalAlign.Center } }
};
protected override void OnInitialized()
{
TaskCollection = GetTaskCollection();
}
public async void ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
{
if (args.Item.Id == "PdfExport")
{
GanttPdfExportProperties exportProperties = new GanttPdfExportProperties();
PdfHeader Header = new PdfHeader()
{
FromTop = 0,
Height = 100,
Contents = HeaderContent
};
PdfFooter Footer = new PdfFooter()
{
FromBottom = 250,
Height = 100,
Contents = FooterContent
};
exportProperties.Header = Header;
exportProperties.Footer = Footer;
if(Gantt!=null)
{
await Gantt.ExportToPdfAsync(exportProperties);
}
}
}
public class TaskData
{
public int TaskId { get; set; }
public string? TaskName { get; set; }
public DateTime StartDate { get; set; }
public DateTime? EndDate { get; set; }
public string? Duration { get; set; }
public int Progress { get; set; }
public int? ParentId { get; set; }
public string? Predecessor { get; set; }
}
public static List<TaskData> GetTaskCollection()
{
List<TaskData> Tasks = new List<TaskData>()
{
new TaskData() { TaskId = 1, TaskName = "Project initiation", StartDate = new DateTime(2026, 01, 05), EndDate = new DateTime(2026, 01, 08), },
new TaskData() { TaskId = 2, TaskName = "Identify Site location", StartDate = new DateTime(2026, 01, 05), Duration = "0", Progress = 30, ParentId = 1, },
new TaskData() { TaskId = 3, TaskName = "Perform soil test", StartDate = new DateTime(2026, 01, 05), EndDate = new DateTime(2026, 01, 08), Progress = 40, ParentId = 1, Predecessor="2", },
new TaskData() { TaskId = 4, TaskName = "Soil test approval", StartDate = new DateTime(2026, 01, 05), Duration = "0", Progress = 30, ParentId = 1, Predecessor="3", },
new TaskData() { TaskId = 5, TaskName = "Project estimation", StartDate = new DateTime(2026, 01, 10), EndDate = new DateTime(2026, 01, 17), },
new TaskData() { TaskId = 6, TaskName = "Develop floor plan for estimation", StartDate = new DateTime(2026, 01, 06), EndDate = new DateTime(2026, 01, 08), Progress = 30, ParentId = 5, Predecessor="4", },
new TaskData() { TaskId = 7, TaskName = "List materials", StartDate = new DateTime(2026, 01, 06), EndDate = new DateTime(2026, 01, 08), Progress = 40, ParentId = 5, Predecessor="6", },
new TaskData() { TaskId = 8, TaskName = "Estimation approval", StartDate = new DateTime(2026, 01, 06), Duration = "0", Progress = 30, ParentId = 5, Predecessor="7", }
};
return Tasks;
}
}Draw a line in header and footer
Customize lines in headers or footers using the Header and Footer properties in GanttPdfExportProperties. To draw a line:
- Set the
Typeproperty to Line. - Use the
Pointsproperty to define the start and end coordinates of the line. - Specify the
PageNumberTypeproperty to determine where the line should appear. - Configure the
Styleproperty to customize color, width, and dash pattern.
These options provide flexibility for adding separators or visual structure to the header and footer areas in the exported PDF.
@using Syncfusion.Blazor.Gantt
@using Syncfusion.Blazor.Grids
<SfGantt @ref="Gantt" ID="GanttExport" DataSource="@TaskCollection" Height="450px" Width="900px" AllowPdfExport="true" Toolbar="toolbarItem">
<GanttTaskFields Id="TaskId" Name="TaskName" StartDate="StartDate" EndDate="EndDate" Dependency="Predecessor"
Duration="Duration" Progress="Progress" ParentID="ParentId">
</GanttTaskFields>
<GanttEvents OnToolbarClick="ToolbarClickHandler" TValue="TaskData"></GanttEvents>
</SfGantt>
@code {
public List<TaskData>? TaskCollection { get; set; }
public SfGantt<TaskData>? Gantt;
private List<object> toolbarItem = new List<Object>() { new Syncfusion.Blazor.Navigations.ToolbarItem() { Text = "PDF Export", TooltipText = "PDF Export", Id = "PdfExport", PrefixIcon = "e-pdfexport" } };
public List<PdfHeaderFooterContent> HeaderContent = new List<PdfHeaderFooterContent>
{
new PdfHeaderFooterContent() { Type = ContentType.Line, Points = new PdfPoints() { X1 = 0, Y1 = 4, X2 = 685, Y2 = 4 }, Style = new PdfContentStyle() { PenColor = "#000080", DashStyle = PdfDashStyle.Solid } }
};
public List<PdfHeaderFooterContent> FooterContent = new List<PdfHeaderFooterContent>
{
new PdfHeaderFooterContent() { Type = ContentType.Line, Points = new PdfPoints() { X1 = 0, Y1 = 350, X2 = 685, Y2 = 350 }, Style = new PdfContentStyle() { PenColor = "#000080", DashStyle = PdfDashStyle.Solid } }
};
protected override void OnInitialized()
{
TaskCollection = GetTaskCollection();
}
public async void ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
{
if (args.Item.Id == "PdfExport")
{
GanttPdfExportProperties exportProperties = new GanttPdfExportProperties();
PdfHeader Header = new PdfHeader()
{
FromTop = 0,
Height = 100,
Contents = HeaderContent
};
PdfFooter Footer = new PdfFooter()
{
FromBottom = 250,
Height = 100,
Contents = FooterContent
};
exportProperties.Header = Header;
exportProperties.Footer = Footer;
await Gantt.ExportToPdfAsync(exportProperties);
}
}
public class TaskData
{
public int TaskId { get; set; }
public string? TaskName { get; set; }
public DateTime StartDate { get; set; }
public DateTime? EndDate { get; set; }
public string? Duration { get; set; }
public int Progress { get; set; }
public int? ParentId { get; set; }
public string? Predecessor { get; set; }
}
public static List<TaskData> GetTaskCollection()
{
List<TaskData> Tasks = new List<TaskData>()
{
new TaskData() { TaskId = 1, TaskName = "Project initiation", StartDate = new DateTime(2026, 01, 05), EndDate = new DateTime(2026, 01, 08), },
new TaskData() { TaskId = 2, TaskName = "Identify Site location", StartDate = new DateTime(2026, 01, 05), Duration = "0", Progress = 30, ParentId = 1, },
new TaskData() { TaskId = 3, TaskName = "Perform soil test", StartDate = new DateTime(2026, 01, 05), EndDate = new DateTime(2026, 01, 08), Progress = 40, ParentId = 1, Predecessor="2", },
new TaskData() { TaskId = 4, TaskName = "Soil test approval", StartDate = new DateTime(2026, 01, 05), Duration = "0", Progress = 30, ParentId = 1, Predecessor="3", },
new TaskData() { TaskId = 5, TaskName = "Project estimation", StartDate = new DateTime(2026, 01, 10), EndDate = new DateTime(2026, 01, 17), },
new TaskData() { TaskId = 6, TaskName = "Develop floor plan for estimation", StartDate = new DateTime(2026, 01, 06), EndDate = new DateTime(2026, 01, 08), Progress = 30, ParentId = 5, Predecessor="4", },
new TaskData() { TaskId = 7, TaskName = "List materials", StartDate = new DateTime(2026, 01, 06), EndDate = new DateTime(2026, 01, 08), Progress = 40, ParentId = 5, Predecessor="6", },
new TaskData() { TaskId = 8, TaskName = "Estimation approval", StartDate = new DateTime(2026, 01, 06), Duration = "0", Progress = 30, ParentId = 5, Predecessor="7", }
};
return Tasks;
}
}