$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
GridView WinForms Control
Export grid data to excel, CSV, HTML, and PDF files in C# WinForms Applications.
Home > WinForms UI Controls > User Manual > Export Grid Data to PDF in C#

Export to PDF from GridView C#.NET

Kettic GridView .NET component for Windows Forms provides the support of exporting to PDF documents. The exporting to PDF will render the GridView to an XHTML table and then convert the table to a PDF document in the process, so the exporting to PDF is capable of all features of exporting to html file. Furthermore, the export to PDF offers more PDF specific functionality. This feature of exporting to PDF is included in the KetticData.dll assembly. To use this method, we should include the Kettic.WinForms.Data and the Kettic.WinForms.UI.Export C# namespaces, which allows us to access to the types contained in KetticData.

How to Export to PDF in C# GridView

To export the grid data to PDF document, we need to initialize the ExportToPdf C# class first. And the constructor will hold the parameter, KetticGridView, to be exported. The simple C# code below demonstrates the approach of initializing the ExportToPdf object.

ExportToPdf exporter = new ExportToPdf(this.ketticGridView1);
When we are going to export the grid data to PDF document, we can use the FileExtension property to modify the default file extension, *.pdf, to the exported result file.

exporter.FileExtension = "pdf";
After initializing the ExportToPdf C# class, we can use the following options to determine how to export data: ExportAlways, DoNotExport, and ExportAsHidden. To accomplish, we need to modify the property of DoNotExport, which is the default setting, to HiddenColumnOption and HiddenRowOption. The C# code below shows how to set the hidden column option.

exporter.HiddenColumnOption = Kettic.WinForms.UI.Export.HiddenOption.DoNotExport;
The ExportToPdf C# class is able to export the visual settings to PDF document. This feature is enabled via modifying the value of EnableAternativeRow property to true. The Kettic GridView also exports the conditional formatting to the PDF document. To enable the functionality of exporting visual settings, set the value of ExportVisualSettings property to true as the C# code snippet below.

exporter.ExportVisualSettings = true;
The exporting to PDF process allows the users to add a page title to the PDF document. This is accomplished by using the PageTitle property, which will display the title on all pages of the PDF document exported. The following is the C# code to set the PageTitle property

exporter.PageTitle = "Title";
The Kettic GridView .NET control offers the SummariesExportOption property to specify how to export summary items. There are four options available for selecting: ExportAll, ExportOnlyTop, ExportOnlyBottom, and DoNotExport. The default setting is ExportAll. The C# code below shows how to set the SummariesExportOption property.

exporter.SummariesExportOption = SummariesOption.ExportAll;
The export to PDF feature provides the support of adjusting the grid content to fit to the width of the PDF page. The C# code below shows how to set the grid to fit to PDF page.

exporter.FitToPageWidth = true;
The export to PDF feature also offers the Scale support, which will change the grid size on the PDF page. The Scale property will increase or decrease the grid size by percentage. The C# code below decreases the grid size of PDF page by 10%.

exporter.Scale = 0.9f;
There is a TableBorderThickness available to the users to adjust the thickness of the table border while exporting to PDF document. As the value of the table border is zero, the border will not be shown. The C# code below shows how to draw the border in the thickness of 1.

exporter.TableBorderThickness = 1;
The export to PDF functionality provides various PDF rendering settings. This is accomplished by using the ExportToPDFSettings property. The valid settings of export to PDF file include: Author, Creator, EnableAdd, EnableCopy, EnableModify, EnablePrinting, FontType, Keywords, Page Margins (PageBottomMargin, PageTopMargin, PageLeftMargin, PageRightMargin, PageFooterMargin), Page Size (PageHeight and PageWidth), Producer, Subject, and Title.

exporter.ExportToPDFSettings.PageHeight = 170;
exporter.ExportToPDFSettings.PageWidth = 280;
After setting the above properties, we can render PDF file now. To export data from grid to PDF document, we need to use the ApplyExport method included in the ExportToPdf object. Its valid parameter includes fileName which define the name of the exported file. The following C# code is to export grid to PDF document.

string fileName = "c:\\DataExportToPDF.pdf";
exporter.RunExport(fileName);
UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls