Thursday, July 4, 2024
HomeC#Simply Export .NET MAUI DataGrid to Particular PDF Web page

Simply Export .NET MAUI DataGrid to Particular PDF Web page


TL;DR: Study to export the Syncfusion .NET MAUI DataGrid content material to a selected web page in a PDF doc. This information contains code examples and setup directions for builders.

Syncfusion .NET MAUI DataGrid management shows and manipulates knowledge in a tabular view. Its wealthy function set contains completely different column varieties, sorting, autofit columns and rows, and styling all components.

This weblog will information you thru the steps to export the .NET MAUI DataGrid to a selected PDF web page.

Observe: In the event you’re new to our Syncfusion .NET MAUI DataGrid, please consult with the getting began documentation.

Exporting .NET MAUI DataGrid to a selected PDF web page

The Syncfusion.Maui.DataGridExport NuGet bundle gives all of the PDF exporting functionalities, permitting us to make the most of PDF packages to export the DataGrid into PDF codecs.

So, embrace the Syncfusion.Maui.DataGridExport bundle in your app NuGet.

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

<StackLayout>
    <Button Textual content="Export To PDF" WidthRequest="200" HeightRequest="50" 
                Clicked="OnExportToPDF" />
    <syncfusion:SfDataGrid x:Title="dataGrid"
                            Margin="20"
                            VerticalOptions="FillAndExpand"
                            ItemsSource="{Binding OrderInfoCollection}"
                            GridLinesVisibility="Each"
                            HeaderGridLinesVisibility="Each"
                            AutoGenerateColumnsMode="None"
                            SelectionMode="A number of"
                            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="Buyer ID"
                                            MappingName="CustomerID">
            </syncfusion:DataGridTextColumn>
            <syncfusion:DataGridTextColumn MappingName="Buyer"
                                            HeaderText="Buyer">
            </syncfusion:DataGridTextColumn>
            <syncfusion:DataGridTextColumn HeaderText="Ship Metropolis"
                                            MappingName="ShipCity">
            </syncfusion:DataGridTextColumn>
            <syncfusion:DataGridTextColumn HeaderText="Ship Nation"
                                            MappingName="ShipCountry">
            </syncfusion:DataGridTextColumn>
        </syncfusion:SfDataGrid.Columns>
    </syncfusion:SfDataGrid>
</StackLayout>

After executing the above code instance, the UI will appear like the next picture.

ExportToPDF button All of the pdf exporting strategies can be found within the DataGridPdfExportingController class. Utilizing the ExportToPdf or ExportToPdfGrid methodology, we will export the DataGrid content material to PDF.

You’ll be able to add the required variety of pages to the PDF doc and point out the web page quantity on which it’s good to render the DataGrid knowledge utilizing the StartPageIndex property.

non-public void OnExportToPDF(object sender, EventArgs e)
{
    MemoryStream stream = new MemoryStream();
    DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
    var pdfDocument = new PdfDocument()
    {
        PageSettings =
        {
            Orientation = PdfPageOrientation.Panorama
        }
    };
    pdfDocument.Pages.Add();
    pdfDocument.Pages.Add();
    pdfDocument.Pages.Add();
    DataGridPdfExportingOption possibility = new DataGridPdfExportingOption() { StartPageIndex = 1, PdfDocument = pdfDocument};            
    var pdfDoc = pdfExport.ExportToPdf(this.dataGrid, possibility);
    SaveService saveService = new();
    saveService.SaveAndView("Export Characteristic.pdf", "software/pdf", stream);
}

Right here, we’ll export the .NET MAUI DataGrid to the second web page in a PDF doc. Confer with the next output picture.

Exporting .NET MAUI DataGrid to a specific page in a PDF
Exporting .NET MAUI DataGrid to a selected web page in a PDF

Observe: You too can export the DataGrid to a selected level in a PDF doc.

GitHub reference

Additionally, try the Exporting .NET MAUI DataGrid to a selected web page in a PDF doc GitHub demo.

Supercharge your cross-platform apps with Syncfusion’s strong .NET MAUI controls.

Strive It Free

Conclusion

Thanks for studying! On this weblog, now we have seen the way to export the Syncfusion .NET MAUI DataGrid to a selected web page in a PDF. We consider that the steps outlined right here have been worthwhile and enlightening.

In the event you’re taken with delving deeper into our .NET MAUI framework, you possibly can simply entry and consider it by downloading Important Studio for .NET MAUI without cost. Our esteemed prospects can purchase the most recent model of Important Studio from the License and Downloads web page.

Do you have to want any help or have additional inquiries, contact us by way of our assist discussion boardassist portal, or suggestions portal. We’re dedicated to offering assist and assist in each attainable method.

Associated blogs

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments