Easily Export .NET MAUI DataGrid to Specific PDF Page
Tags: dotnetmaui, datagrid, export, maui
Published: 2024-07-08 15:59:48

---
title: Easily Export .NET MAUI DataGrid to Specific PDF Page
published: true
date: 2024-07-02 10:00:00 UTC
tags: dotnetmaui, datagrid, export, maui
canonical_url: https://www.syncfusion.com/blogs/post/export-maui-grid-to-specific-pdf-page
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f6uche1fo3tor45y4uvs.png
---
**TL;DR:** Learn to export the Syncfusion .NET MAUI DataGrid content to a specific page in a PDF document. This guide includes code examples and setup instructions for developers.

Syncfusion [.NET MAUI DataGrid](https://www.syncfusion.com/maui-controls/maui-datagrid ".NET MAUI DataGrid") control displays and manipulates data in a tabular view. Its rich feature set includes different column types, sorting, autofit columns and rows, and styling all elements.

This blog will guide you through the steps to export the .NET MAUI DataGrid to a specific PDF page.

**Note:** If you’re new to our Syncfusion .NET MAUI DataGrid, please refer to the [getting started documentation](https://help.syncfusion.com/maui/datagrid/getting-started "Getting started with .NET MAUI DataGrid").

## Exporting .NET MAUI DataGrid to a specific PDF page

The [Syncfusion.Maui.DataGridExport](https://www.nuget.org/packages/Syncfusion.Maui.DataGridExport "Syncfusion.Maui.DataGridExport NuGet package") NuGet package offers all the PDF exporting functionalities, allowing us to utilize PDF packages to export the DataGrid into PDF formats.

So, include the **Syncfusion.Maui.DataGridExport** package in your app NuGet.

Then, add the Syncfusion .NET MAUI DataGrid control and an **Export To PDF** button to your xaml page.

```xml
<StackLayout>
    <Button Text="Export To PDF" WidthRequest="200" HeightRequest="50" 
                Clicked="OnExportToPDF" />
    <syncfusion:SfDataGrid x:Name="dataGrid"
                            Margin="20"
                            VerticalOptions="FillAndExpand"
                            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>

```

After executing the above code example, the UI will look like the following image.
![ExportToPDF button](https://www.syncfusion.com/blogs/wp-content/uploads/2024/07/ExportToPDF-button.png) All the pdf exporting methods are available in the [DataGridPdfExportingController](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.Exporting.DataGridPdfExportingController.html "DataGridPdfExportingController class of .NET MAUI DataGrid") class. Using the [ExportToPdf](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.Exporting.DataGridPdfExportingController.html#Syncfusion_Maui_DataGrid_Exporting_DataGridPdfExportingController_ExportToPdf_Syncfusion_Maui_DataGrid_SfDataGrid_ "ExportToPdf method of .NET MAUI DataGrid") or [ExportToPdfGrid](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.Exporting.DataGridPdfExportingController.html#Syncfusion_Maui_DataGrid_Exporting_DataGridPdfExportingController_ExportToPdfGrid_Syncfusion_Maui_DataGrid_SfDataGrid_Syncfusion_Maui_Data_ICollectionViewAdv_Syncfusion_Maui_DataGrid_Exporting_DataGridPdfExportingOption_Syncfusion_Pdf_PdfDocument_ "ExportToPdfGrid method of .NET MAUI DataGrid") method, we can export the DataGrid content to PDF.

You can add the required number of pages to the PDF document and mention the page number on which you need to render the DataGrid data using the [StartPageIndex](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.Exporting.DataGridPdfExportingOption.html#Syncfusion_Maui_DataGrid_Exporting_DataGridPdfExportingOption_StartPageIndex "StartPageIndex property of .NET MAUI DataGrid") property.

```csharp
private void OnExportToPDF(object sender, EventArgs e)
{
    MemoryStream stream = new MemoryStream();
    DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
    var pdfDocument = new PdfDocument()
    {
        PageSettings =
        {
            Orientation = PdfPageOrientation.Landscape
        }
    };
    pdfDocument.Pages.Add();
    pdfDocument.Pages.Add();
    pdfDocument.Pages.Add();
    DataGridPdfExportingOption option = new DataGridPdfExportingOption() { StartPageIndex = 1, PdfDocument = pdfDocument};            
    var pdfDoc = pdfExport.ExportToPdf(this.dataGrid, option);
    SaveService saveService = new();
    saveService.SaveAndView("Export Feature.pdf", "application/pdf", stream);
}
```

Here, we’ll export the .NET MAUI DataGrid to the second page in a PDF document. Refer to the following output image.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2024/07/Exporting-.NET-MAUI-DataGrid-to-a-specific-page-in-a-PDF.png" alt="Exporting .NET MAUI DataGrid to a specific page in a PDF" style="width:100%">

  <figcaption>Exporting .NET MAUI DataGrid to a specific page in a PDF</figcaption>

</figure>

**Note:** You can also [export the DataGrid to a specific point in a PDF document](https://help.syncfusion.com/maui/datagrid/export-to-pdf#startpoint "Exporting .NET MAUI DataGrid to a specific starting point on a PDF page").

## GitHub reference

Also, check out the [Exporting .NET MAUI DataGrid to a specific page in a PDF document GitHub demo](https://github.com/SyncfusionExamples/Exporting-datagrid-to-specific-PDF-page-in-.NET-MAUI "Exporting .NET MAUI DataGrid to a specific page in a PDF document GitHub demo").

## Conclusion

Thanks for reading! In this blog, we have seen how to export the Syncfusion [.NET MAUI DataGrid](https://www.syncfusion.com/maui-controls/maui-datagrid ".NET MAUI DataGrid") to a specific page in a PDF. We believe that the steps outlined here have been valuable and enlightening.

If you’re interested in delving deeper into our .NET MAUI framework, you can easily access and evaluate it by downloading [Essential Studio for .NET MAUI](https://www.syncfusion.com/downloads/maui "Free evaluation of the Essential Studio for .NET MAUI") for free. Our esteemed customers can acquire the latest version of Essential Studio from the [License and Downloads ](https://www.syncfusion.com/account/downloads "Essential Studio license and downloads page")page.

Should you need any assistance or have further inquiries, contact us via our [support forum](https://www.syncfusion.com/forums "Syncfusion Support Forum"), [support portal](https://support.syncfusion.com/ "Syncfusion Support Portal"), or [feedback portal](https://www.syncfusion.com/feedback/ "Syncfusion Feedback Portal"). We are committed to providing help and support in every possible way.

## Related blogs

- [Exporting DataGrid to PDF Made Easy in .NET MAUI](https://www.syncfusion.com/blogs/post/export-dotnet-maui-datagrid-to-pdf "Blog: Exporting DataGrid to PDF Made Easy in .NET MAUI")
- [Syncfusion Essential Studio 2024 Volume 2 Is Here!](https://www.syncfusion.com/blogs/post/syncfusion-essential-studio-2024-vol2 "Blog: Syncfusion Essential Studio 2024 Volume 2 Is Here!")
- [Introducing the 12th Set of New .NET MAUI Controls and Features](https://www.syncfusion.com/blogs/post/syncfusion-dotnet-maui-2024-volume-2 "Blog: Introducing the 12th Set of New .NET MAUI Controls and Features")
- [Introducing the New .NET MAUI Digital Gauge Control](https://www.syncfusion.com/blogs/post/dotnetmaui-digital-gauge-control "Blog: Introducing the New .NET MAUI Digital Gauge Control")