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 add page numbers to the exported pdf document in WinForms DataGrid (SfDataGrid)?

Platform: WinForms |
Control: SfDataGrid

Adding page number to exported pdf document

You can add page numbers in the header or footer of the exported PDF document using the dynamic fields: PdfPageNumberField and PdfCompositeField.


PdfExportingOptions options = new PdfExportingOptions();
options.RepeatHeaders = true;
options.ExportGroupSummary = true;
options.ExportFormat = true;
options.FitAllColumnsInOnePage = false;
options.ExportTableSummary = true;
//Set document information.
Syncfusion.Pdf.PdfDocument document = new Syncfusion.Pdf.PdfDocument();
RectangleF bounds = new RectangleF(0, 10, document.Pages[0].GetClientSize().Width, 50);
PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds);
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 7);
PdfBrush brush = new PdfSolidBrush(Color.Black);
//Create page number field.
PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);
//Add the fields in composite fields.
PdfCompositeField compositeField = new PdfCompositeField(font, brush, "{0}", pageNumber);
compositeField.Bounds = footer.Bounds;
//Draw the composite field in footer.
compositeField.Draw(footer.Graphics, new PointF(250, 40));
//Add the footer template at the bottom.
document.Template.Bottom = footer;
var pdfGrid = sfDataGrid1.ExportToPdfGrid(sfDataGrid1.View, options);
pdfGrid.Draw(page, new PointF());


Dim options As New PdfExportingOptions()
options.RepeatHeaders = True
options.ExportGroupSummary = True
options.ExportFormat = True
options.FitAllColumnsInOnePage = False
options.ExportTableSummary = True
'Set document information.
Dim document As New Syncfusion.Pdf.PdfDocument()
Dim page = document.Pages.Add()
Dim bounds As New RectangleF(0, 10, document.Pages(0).GetClientSize().Width, 50)
Dim footer As New PdfPageTemplateElement(bounds)
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 7)
Dim brush As PdfBrush = New PdfSolidBrush(Color.Black)
'Create page number field.
Dim pageNumber As New PdfPageNumberField(font, brush)
'Add the fields in composite fields.
Dim compositeField As New PdfCompositeField(font, brush, "{0}", pageNumber)
compositeField.Bounds = footer.Bounds
'Draw the composite field in footer.
compositeField.Draw(footer.Graphics, New PointF(250, 40))
'Add the footer template at the bottom.
document.Template.Bottom = footer
Dim pdfGrid = sfDataGrid1.ExportToPdfGrid(sfDataGrid1.View, options)
pdfGrid.Draw(page, New PointF())


C# : PageNumber

VB : PageNumber

Reference link: https://help.syncfusion.com/windowsforms/datagrid/exporttopdf

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

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