New to Telerik UI for WinUI? Download free 30-day trial

Export to PDF

The export feature allows you to save the data from the DataGrid component to few different formats. This article shows how to save it to PDF.

Exporting the Document

The feature works with the Export and ExportAsync methods of RadDataGrid. The methods allow you to provide a stream (usually pointing to a file), a document format and export options objects.

Export DataGrid to PDF format

string projectRootFolderPath = System.IO.Path.GetFullPath("../../../../../../", AppDomain.CurrentDomain.BaseDirectory); 
using (var stream = File.Open(projectRootFolderPath + "\" + "SampleDocument.pdf", FileMode.OpenOrCreate)) 
{ 
    this.dataGrid.Export(stream, ExportFormat.Pdf); 
} 
To include additional settings for the document, use the DataGridExportOptions class. Read more about the available settings in the Modifying Exported Data article.

Using the DataGridExportOptions

string projectRootFolderPath = System.IO.Path.GetFullPath("../../../../../../", AppDomain.CurrentDomain.BaseDirectory); 
using (var stream = File.Open(projectRootFolderPath + "\" + "SampleDocument.pdf", FileMode.OpenOrCreate)) 
{ 
    this.dataGrid.Export(stream, ExportFormat.Pdf, new DataGridExportOptions() 
    { 
        AutoFitColumnsWidth = true, 
        ShowColumnFooters = true, 
        ShowColumnHeaders = false, 
        IgnoreCollapsedGroups = true 
    }); 
} 

The exporting process can be customized at runtime using the ElementExporting and ElementExported events of RadDataGrid. Read more in the Modifying Exported Data article.

See Also

In this article
Not finding the help you need?