Articles in this section

How to Export .NET MAUI DataGrid Image Column to PDF Document?

In this article, we will show you how to export a DataGridImagecolumn to a PDF document in the .NET MAUI DataGrid.

xaml
The code below illustrates how to export a DataGridImagecolumn to a PDF document in DataGrid.

 <ContentPage.BindingContext>
     <local:EmployeeViewModel/>
 </ContentPage.BindingContext>

 <StackLayout>
    <syncfusion:SfDataGrid x:Name="dataGrid" VerticalOptions="FillAndExpand" AutoGenerateColumnsMode="None" ColumnWidthMode="Auto"
                           ItemsSource="{Binding Employees}">
        <syncfusion:SfDataGrid.Columns>
            <syncfusion:DataGridNumericColumn MappingName="EmployeeID"
                                              Format="#"
                                              HeaderText="Employee ID" />
            <syncfusion:DataGridTextColumn MappingName="Name"
                                           HeaderText="Employee Name" />

            <syncfusion:DataGridImageColumn MappingName="EmpImage"
                                            Width="75"
                                            HeaderText="Image" />
        </syncfusion:SfDataGrid.Columns>
    </syncfusion:SfDataGrid>
    <Button Text="ExportToPdf" Clicked="Button_Clicked"> </Button>
</StackLayout>

C#

private void Button_Clicked(object sender, EventArgs e)
{
    MemoryStream stream = new MemoryStream();
    DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
    DataGridPdfExportingOption option = new DataGridPdfExportingOption();
    option.CanExportColumnWidth = true;
    var pdfDoc = new PdfDocument();
    pdfDoc = pdfExport.ExportToPdf(this.dataGrid, option);
    pdfDoc.Save(stream);
    pdfDoc.Close(true);
    SaveService saveService = new();
    saveService.SaveAndView("ExportFeature.pdf", "application/pdf", stream); ;
}

Note

If your image source is an embedded resource, you can fetch the image as shown below:

var img = ImageSource.FromResource("DataGridSample.Resources.Images.image0.png", typeof(EmployeeViewModel).GetTypeInfo().Assembly);

Output

ExportImageColumn.png

Download the complete sample from GitHub

Conclusion

I hope you enjoyed learning how to export a .NET MAUI DataGrid image column to a PDF document.

You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations and Documentation, and how to quickly get started with configuration specifications. Explore our .NET MAUI DataGrid example to understand how to create and manipulate data.

For current customers, check out our components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.

Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied