I export the radgridview to pdf with header and footer. How to have multiple lines of header with different font size?
Telerik.WinControls.Export.GridViewPdfExport exporter = new Telerik.WinControls.Export.GridViewPdfExport(this.radGridView1);
Thanks.
3 Answers, 1 is accepted
0
Hello, Bertha,
GridViewPdfExport has a public API for applying a certain font for the header. You can specify left, right or middle header. Multiline header text with different fonts is not supported out of the box. However, it is possible to customize the default rendering of the header. For this purpose it is necessary to create a GridViewPdfExport and override its DrawHeader method. Note that GridViewPdfExport utilizes the powerful RadPdfProcessing library and exports RadGridView`s data natively to the PDF format. Additional information about the library and the API it offers is available in the online documentation: https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview
Here is the sample code snippet for showing two line header with different font:
Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it in a way which suits your requirement best.

I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess
Progress Telerik
GridViewPdfExport has a public API for applying a certain font for the header. You can specify left, right or middle header. Multiline header text with different fonts is not supported out of the box. However, it is possible to customize the default rendering of the header. For this purpose it is necessary to create a GridViewPdfExport and override its DrawHeader method. Note that GridViewPdfExport utilizes the powerful RadPdfProcessing library and exports RadGridView`s data natively to the PDF format. Additional information about the library and the API it offers is available in the online documentation: https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview
Here is the sample code snippet for showing two line header with different font:
private void radButton1_Click(object sender, EventArgs e){ string fileName = @"..\..\export" + DateTime.Now.ToLongTimeString().Replace(":", "_") + ".pdf"; CustomGridViewPdfExport pdfExporter = new CustomGridViewPdfExport(this.radGridView1); pdfExporter.ShowHeaderAndFooter = true; pdfExporter.RunExport(fileName, new Telerik.WinControls.Export.PdfExportRenderer()); Process.Start(fileName);}public class CustomGridViewPdfExport : GridViewPdfExport{ public CustomGridViewPdfExport(Telerik.WinControls.UI.RadGridView radGridView) : base(radGridView) { } protected override void DrawHeader() { System.Reflection.FieldInfo fi = typeof(GridViewPdfExport).GetField("editor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); PdfEditor editor = fi.GetValue(this) as PdfEditor; if (!this.ShowHeaderAndFooter) { return; } editor.SavePosition(); editor.CreateMatrixPosition(); editor.TranslatePosition(this.PageMargins.Left, this.PageMargins.Top); editor.SaveProperties(); //specify the font for the first line this.HeaderFont = new System.Drawing.Font("Arial", 14f, FontStyle.Italic); editor.SetTextFontSize(this.HeaderFont.Size); editor.TrySetFont(this.HeaderFont.Name, this.HeaderFont.Style); //draw the first line editor.DrawText("First"); editor.TranslatePosition(this.PageMargins.Left - 20, this.PageMargins.Top); //specify the font for the second line this.HeaderFont = new System.Drawing.Font("Verdana", 10f, FontStyle.Bold); editor.SetTextFontSize(this.HeaderFont.Size); editor.TrySetFont(this.HeaderFont.Name, this.HeaderFont.Style); //draw the second line editor.DrawText("Second"); editor.RestoreProperties(); editor.RestorePosition(); }}Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it in a way which suits your requirement best.
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Bertha
Top achievements
Rank 1
answered on 28 Sep 2018, 07:46 PM
Extremely helpful examples.
I want to push the grid table to lower position so I have more room for header. If I use the GridViewPdfExport without customize, the grid table with Header is lower than the one customize with Header.
How can I push the grid table down?
Thanks.
0
Hello Bertha,
You can push the grid down inside the exported document, by increasing the HeaderHeight property of the GridViewPdfExport object. For example, you can test like this:
I hope this will help. Let me know if you need further assistance.
Regards,
Hristo
Progress Telerik
You can push the grid down inside the exported document, by increasing the HeaderHeight property of the GridViewPdfExport object. For example, you can test like this:
CustomGridViewPdfExport pdfExporter = new CustomGridViewPdfExport(this.radGridView1);pdfExporter.ShowHeaderAndFooter = true;pdfExporter.HeaderHeight = 100;I hope this will help. Let me know if you need further assistance.
Regards,
Hristo
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.

