|
1 | 1 | --- |
2 | 2 | layout: post |
3 | | -title: Adding header and footer in Blazor DataGrid | Syncfusion |
4 | | -description: Checkout and learn here all about adding header and footer in PDF export using Syncfusion Blazor DataGrid and much more details. |
| 3 | +title: Customize PDF headers and footers in the Blazor DataGrid | Syncfusion |
| 4 | +description: Learn how to customize headers and footers in PDF export using Syncfusion Blazor DataGrid, including text, images, and page settings. |
5 | 5 | platform: Blazor |
6 | 6 | control: DataGrid |
7 | 7 | documentation: ug |
8 | 8 | --- |
9 | 9 |
|
10 | 10 | # Adding header and footer in Blazor DataGrid |
11 | 11 |
|
12 | | -The Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid allows you to add customized header and footer sections in the exported PDF document. This feature enables you to include custom text, page numbers, lines, page size, and even change the orientation of the header and footer. |
| 12 | +The Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid supports customizing header and footer sections in PDF exports. These regions can include: |
13 | 13 |
|
14 | | -## Adding text in header and footer |
| 14 | +* **Text** – Titles, dates, or disclaimers. |
| 15 | +* **Page Numbers** – For easy navigation. |
| 16 | +* **Lines** – To visually separate sections. |
| 17 | +* **Images** – Such as logos or branding elements. |
| 18 | +* **Layout Adjustments** – Page size and orientation. |
15 | 19 |
|
16 | | -The Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid allows you to add custom text in the header and footer section in the exported PDF document. |
| 20 | +## Adding text in header and footer |
17 | 21 |
|
18 | | -The header section of a PDF document is typically located at the top of each page. It provides space for including additional information or branding elements, such as a company logo, document title, date, or any other content you want to display consistently on every page of the PDF document. |
| 22 | +The Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid supports adding custom text to header and footer regions in PDF exports. |
19 | 23 |
|
20 | | -The footer section, on the other hand, appears at the bottom of each page. It's commonly used to include custom text such as page numbers, copyright information, or disclaimers. Like the header, the footer content is repeated on every page of the document. |
| 24 | +* The **header** appears at the top of each page and can include elements such as a document title, company logo, or date and metadata. This section is typically used for branding and document identification. |
21 | 25 |
|
22 | | -To add text in the header and footer of the exported PDF document, follow these steps: |
| 26 | +* The **footer** appears at the bottom of each page and commonly contains page numbers, copyright text, or disclaimers. This section is useful for navigation and compliance information. |
23 | 27 |
|
24 | | -* Access the [PdfExportProperties](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportProperties.html) of the Grid. |
25 | | -* Set the [Header](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportPropertiesBase.html#Syncfusion_Blazor_Grids_PdfExportPropertiesBase_Header) and [Footer](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportPropertiesBase.html#Syncfusion_Blazor_Grids_PdfExportPropertiesBase_Footer) property to a string value representing the desired text. |
26 | | -* Using [ExportToPdfAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_ExportToPdfAsync_Syncfusion_Blazor_Grids_PdfExportProperties_) method to trigger the PDF export operation. |
| 28 | +To add text in the header and footer of the exported PDF: |
27 | 29 |
|
28 | | -The following example demonstrates how to add text in the header and footer of the exported PDF document: |
| 30 | +1. Access `[PdfExportProperties](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportProperties.html). |
| 31 | +2. Assign [Header](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportPropertiesBase.html#Syncfusion_Blazor_Grids_PdfExportPropertiesBase_Header) and [Footer](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportPropertiesBase.html#Syncfusion_Blazor_Grids_PdfExportPropertiesBase_Footer) using [PdfHeader](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfHeader.html) and [PdfFooter](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfFooter.html) objects. |
| 32 | +3. Add one or more [PdfHeaderFooterContent](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfHeaderFooterContent.html) items to the `Contents` collection for each region. |
| 33 | +4. Call [ExportToPdfAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_ExportToPdfAsync_Syncfusion_Blazor_Grids_PdfExportProperties_) to export with the configured header and footer. |
29 | 34 |
|
30 | 35 | {% tabs %} |
31 | 36 | {% highlight razor tabtitle="Index.razor" %} |
@@ -164,23 +169,24 @@ public class OrderData |
164 | 169 |
|
165 | 170 | ## Draw a line in header and footer |
166 | 171 |
|
167 | | -When exporting data from the Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid to a PDF document, you have an option to draw lines in the header and footer sections. This feature allows you to enhance the visual appearance of the exported PDF document and create a clear separation between the header/footer and the content. |
| 172 | +The Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid supports drawing lines in header and footer regions when exporting to PDF. **Lines** are commonly used to visually separate these regions from the main content. |
168 | 173 |
|
169 | | -You can achieve this by using the [PdfDashStyle](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfDashStyle.html) property, which defines the style of the line drawn. The supported [PdfDashStyle](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfDashStyle.html#fields) include: |
| 174 | +**Supported Line Styles** |
170 | 175 |
|
171 | | -* Dash |
172 | | -* Dot |
173 | | -* DashDot |
174 | | -* DashDotDot |
175 | | -* Solid |
| 176 | +The line style is controlled using the [PdfDashStyle](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfDashStyle.html) enumeration. Available styles include: |
176 | 177 |
|
177 | | -To draw a line in the header and footer of the exported PDF document: |
| 178 | +- Dash |
| 179 | +- Dot |
| 180 | +- DashDot |
| 181 | +- DashDotDot |
| 182 | +- Solid |
178 | 183 |
|
179 | | -* Access the `Header.Contents` and `Footer.Contents` properties from the [Header] (https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportPropertiesBase.html#Syncfusion_Blazor_Grids_PdfExportPropertiesBase_Header) and [Footer](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportPropertiesBase.html#Syncfusion_Blazor_Grids_PdfExportPropertiesBase_Footer) sections of the [PdfExportProperties](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportProperties.html). |
| 184 | +To draw a line in the header and footer: |
180 | 185 |
|
181 | | -* Customize these sections to include a line with the desired dash style using the `PdfDashStyle` options. |
182 | | - |
183 | | -The following example demonstrates how to draw a line in the header and footer of the exported PDF document using a [DropDownList](https://blazor.syncfusion.com/documentation/dropdown-list/getting-started-with-web-app) to dynamically select a line style: |
| 186 | +1. Access Header.Contents and Footer.Contents in [PdfExportProperties](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportProperties.html). |
| 187 | +2. Add [PdfHeaderFooterContent](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfHeaderFooterContent.html) items and set the [ContentType](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ContentType.html#Syncfusion_Blazor_Grids_ContentType) to [Line](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ContentType.html#Syncfusion_Blazor_Grids_ContentType_Line). |
| 188 | +3. Configure Style properties such as `DashStyle`, `PenColor`, and `PenSize`. |
| 189 | +4. Define line coordinates using `Points`. |
184 | 190 |
|
185 | 191 | {% tabs %} |
186 | 192 | {% highlight razor tabtitle="Index.razor" %} |
@@ -367,26 +373,25 @@ public class OrderData |
367 | 373 |
|
368 | 374 | ## Add page number in header and footer |
369 | 375 |
|
370 | | -When exporting data from the Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid to a PDF document, you have an option to include page numbers in the header and footer section. This feature helps improve document navigation by providing consistent page references. |
371 | | - |
372 | | -This can be achieved using the [PdfExportProperties](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportProperties.html) property, which allows customization of the header and footer content. Page numbers can be inserted using the [ContentType.PageNumber](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ContentType.html#Syncfusion_Blazor_Grids_ContentType_PageNumber) setting in the [PdfHeaderFooterContent](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfHeaderFooterContent.html). |
| 376 | +The Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid supports adding page numbers to header and footer regions when exporting to PDF. This feature improves document navigation and readability. |
373 | 377 |
|
374 | | -You can choose from the following [PageNumberType](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfPageNumberType.html#fields) formats: |
| 378 | +Page numbers are configured using [PdfExportProperties](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportProperties.html). Set the [ContentType](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ContentType.html#Syncfusion_Blazor_Grids_ContentType) to [PageNumber](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ContentType.html#Syncfusion_Blazor_Grids_ContentType_PageNumber) when adding page numbers to the header or footer. |
375 | 379 |
|
376 | | -* LowerLatin - a, b, c, |
377 | | -* UpperLatin - A, B, C, |
378 | | -* LowerRoman - i, ii, iii, |
379 | | -* UpperRoman - I, II, III, |
380 | | -* Number - 1,2,3, |
381 | | -* Arabic - 1,2,3. |
| 380 | +The display format is controlled by [PageNumberType](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfPageNumberType.html#fields), which supports: |
382 | 381 |
|
383 | | -To add page numbers to the header and footer of the exported PDF document: |
| 382 | +* Arabic – 1, 2, 3 |
| 383 | +* Number – 1, 2, 3 |
| 384 | +* LowerLatin – a, b, c |
| 385 | +* UpperLatin – A, B, C |
| 386 | +* LowerRoman – i, ii, iii |
| 387 | +* UpperRoman – I, II, III |
384 | 388 |
|
385 | | -* Access the `Header.Contents` and `Footer.Content`s properties of the [Header](https://ej2.syncfusion.com/angular/documentation/api/grid/pdfExportProperties/#header) and [Footer](https://ej2.syncfusion.com/angular/documentation/api/grid/pdfExportProperties/#footer) sections in the `PdfExportProperties`. |
| 389 | +To add page numbers: |
386 | 390 |
|
387 | | -* Set the ContentType to `PageNumber` and define the desired page number format using `PageNumberType`. |
388 | | - |
389 | | -The following example demonstrates how to add a page number in the header and footer of the exported PDF document using a [DropDownList](https://blazor.syncfusion.com/documentation/dropdown-list/getting-started-with-web-app) to dynamically select the page number format: |
| 391 | +1. Add content items to the header and/or footer and set the content type to `PageNumber`. |
| 392 | +2. Specify the page number format using `PageNumberType`. |
| 393 | +3. Define position and style properties as needed. |
| 394 | +4. Call [ExportToPdfAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_ExportToPdfAsync_Syncfusion_Blazor_Grids_PdfExportProperties_) to generate the PDF with page numbers. |
390 | 395 |
|
391 | 396 | {% tabs %} |
392 | 397 | {% highlight razor tabtitle="Index.razor" %} |
@@ -535,17 +540,15 @@ public class OrderData |
535 | 540 |
|
536 | 541 | ## Insert an image in header and footer |
537 | 542 |
|
538 | | -The Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid have an option to include images in the header and footer section when exporting data from the Grid to PDF document. This feature allows you to add a custom logo, branding, or any relevant images to enhance the appearance of the exported PDF document. |
539 | | - |
540 | | -Images can be inserted using a Base64-encoded string in the .jpeg format. This can be achieved using the [PdfExportProperties](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportProperties.html) property of the Grid. |
541 | | - |
542 | | -To insert an image in the header and footer of the exported PDF document, follow these steps: |
543 | | - |
544 | | -* Convert your desired image to a Base64 string in the .jpeg format. |
| 543 | +The Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid supports adding images, such as company logos, to header and footer regions when exporting to PDF. This feature is useful for branding and document personalization. |
545 | 544 |
|
546 | | -* Access the `PdfExportProperties` and assign the Base64 string or image file path to the `Src` property of the corresponding entry in the `Header.Contents` or `Footer.Contents` collection. |
| 545 | +To insert an image: |
547 | 546 |
|
548 | | -The following example demonstrates how to insert an image in header and footer of the exported PDF document: |
| 547 | +1. Convert the image to a **Base64 string** in **JPEG** format. |
| 548 | +2. Access [PdfExportProperties](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportProperties.html) and add content items to the [header](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportPropertiesBase.html#Syncfusion_Blazor_Grids_PdfExportPropertiesBase_Header) and/or [footer](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportPropertiesBase.html#Syncfusion_Blazor_Grids_PdfExportPropertiesBase_Footer). |
| 549 | +3. Set the [ContentType](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ContentType.html#Syncfusion_Blazor_Grids_ContentType) to [Image](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ContentType.html#Syncfusion_Blazor_Grids_ContentType_Image) and assign the **Base64 string** to the `Src` property. |
| 550 | +4. Define the image position and size using `Position` and `Size` properties. |
| 551 | +5. Call [ExportToPdfAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_ExportToPdfAsync_Syncfusion_Blazor_Grids_PdfExportProperties_) to generate the PDF with the configured image. |
549 | 552 |
|
550 | 553 | {% tabs %} |
551 | 554 | {% highlight razor tabtitle="Index.razor" %} |
@@ -666,11 +669,12 @@ public class OrderData |
666 | 669 |
|
667 | 670 | ## Repeat column header on every page |
668 | 671 |
|
669 | | -When exporting data from the Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid to a PDF document, you have an option to repeat the column headers on every page. This feature ensures that the column headers remains visible and easily identifiable, even when the data spans multiple pages in the exported PDF document. |
| 672 | +The Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid supports repeating column headers on every page of a PDF export. This ensures headers remain visible when the content spans multiple pages. By default, headers appear only on the first page. |
670 | 673 |
|
671 | | -By default, the column headers is occurs only on the first page of the PDF document. However, you can enable the [IsRepeatHeader](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportProperties.html#Syncfusion_Blazor_Grids_PdfExportProperties_IsRepeatHeader) property of the [PdfExportProperties](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportProperties.html) class to display the column headers on every page. This can be achieved using the [PdfHeaderQueryCellInfo](https://ej2.syncfusion.com/angular/documentation/api/grid/#pdfheaderquerycellinfo) event of the Grid. |
| 674 | +To enable this feature: |
672 | 675 |
|
673 | | -The following example demonstrates how to repeat the column headers on every page of the exported PDF document using the `PdfHeaderQueryCellInfo` event: |
| 676 | +1. Set the [IsRepeatHeader](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportProperties.html#Syncfusion_Blazor_Grids_PdfExportProperties_IsRepeatHeader) property in [PdfExportProperties](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfExportProperties.html) to **true**. |
| 677 | +2. Optionally, customize header appearance using the [PdfHeaderQueryCellInfo](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEvents-1.html#Syncfusion_Blazor_Grids_GridEvents_1_PdfHeaderQueryCellInfoEvent) event. |
674 | 678 |
|
675 | 679 | {% tabs %} |
676 | 680 | {% highlight razor tabtitle="Index.razor" %} |
|
0 commit comments