This Sample demonstrates how to Exporting DataGrid to PDF Made Easy in Syncfusion .NET Maui DataGrid(SfDataGrid).
<ContentPage.BindingContext>
<local:OrderInfoRepository x:Name="viewModel" />
</ContentPage.BindingContext>
<ContentPage.Content>
<StackLayout>
<Button Text="Export To PDF" WidthRequest="200" HeightRequest="50"
Clicked="ExportToPdf_Clicked" />
<syncfusion:SfDataGrid x:Name="dataGrid"
Margin="20"
ItemsSource="{Binding OrderInfoCollection}"
GridLinesVisibility="Both"
HeaderGridLinesVisibility="Both"
AutoGenerateColumnsMode="None"
SelectionMode="Multiple"
ColumnWidthMode="Auto">
<syncfusion:SfDataGrid.DefaultStyle>
<syncfusion:DataGridStyle RowBackground="LightBlue" HeaderRowBackground="LightGoldenrodYellow"/>
</syncfusion:SfDataGrid.DefaultStyle>
<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridNumericColumn Format="D"
HeaderText="Order ID"
MappingName="OrderID">
</syncfusion:DataGridNumericColumn>
<syncfusion:DataGridTextColumn HeaderText="Customer ID"
MappingName="CustomerID">
</syncfusion:DataGridTextColumn>
<syncfusion:DataGridTextColumn MappingName="Customer"
HeaderText="Customer">
</syncfusion:DataGridTextColumn>
<syncfusion:DataGridTextColumn HeaderText="Ship City"
MappingName="ShipCity">
</syncfusion:DataGridTextColumn>
<syncfusion:DataGridTextColumn HeaderText="Ship Country"
MappingName="ShipCountry">
</syncfusion:DataGridTextColumn>
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>
</StackLayout>
</ContentPage.Content>
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void ExportToPdf_Clicked(object sender, EventArgs e)
{
MemoryStream stream = new MemoryStream();
DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
DataGridPdfExportingOption option = new DataGridPdfExportingOption();
var pdfDoc = pdfExport.ExportToPdf(this.dataGrid, option);
pdfDoc.Save(stream);
pdfDoc.Close(true);
SaveService saveService = new();
saveService.SaveAndView("Export Feature.pdf", "application/pdf", stream);
}
}
You can download this example on GitHub.
Take a moment to explore this documentation, where you can find more information about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples. Please refer to this link to learn about the essential features of Syncfusion .NET MAUI DataGrid (SfDataGrid).
I hope you enjoyed learning about How to bind a dynamic data object in SfDataGrid.
You can refer to our .NET MAUI DataGrid’s feature tour page to learn about its other groundbreaking feature representations. You can also explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data. For current customers, you can check out our .NET MAUI components on the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to explore our .NET MAUI DataGrid and other .NET MAUI components.
If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our support forums,Direct-Trac or feedback portal, or the feedback portal. We are always happy to assist you!