We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to create Header and Footer in PDF document?

Platform: Xamarin.Forms |
Control: SfDataGrid

SfDataGrid provides support for exporting the data to PDF with header and footer. You can export the data to PDF by using the ExportToPdf method by passing the SfDataGrid as an argument. You can create the header and footer in the HeaderAndFooterExporting event using the PdfDocumentTemplate property from the event arugment.

The below code illustrates how to hook the HeaderAndFooterExporting event and create header and footer for the exported PDF document.




Sample Link:

How to create Header and Footer in PDF document?

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
You must log in to leave a comment
Apr 12, 2021

Hello, when there are multiple pages, how can I show the footer on the last page? I try like this;

  private async void ToolbarItem_Clicked(object sender, EventArgs e)

            DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
            pdfExport.HeaderAndFooterExporting += PdfExport_HeaderAndFooterExporting;

            MemoryStream stream = new MemoryStream();
            var exportToPdf = pdfExport.ExportToPdf(this.dataGrid, new DataGridPdfExportOption()
                FitAllColumnsInOnePage = true,
                ExportColumnWidth = true,
                ApplyGridStyle = true,

                PdfPageTemplateElement footer = AddFooter(exportToPdf);
                exportToPdf.Pages[exportToPdf.Pages.Count - 1].Section.Template.ApplyDocumentBottomTemplate = true;
                exportToPdf.Pages[exportToPdf.Pages.Count - 1].Section.Template.Bottom = footer; 
        public PdfPageTemplateElement AddFooter(PdfDocument doc)
            float Width = doc.Pages[0].GetClientSize().Width;          

            PdfPageTemplateElement footer = new PdfPageTemplateElement(Width, 220);

            return footer;
        private void PdfExport_HeaderAndFooterExporting(object sender, PdfHeaderFooterEventArgs e)

            float Width = e.PdfPage.GetClientSize().Width;
            PdfPageTemplateElement header = new PdfPageTemplateElement(Width, 225);
e.PdfDocumentTemplate.Top = header;

but didn't work

Apr 12, 2021

In fact, this code may seem to work, but according to the data coming from the datagrid, it is below the grid

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile