We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Datagrid Export To PDF with GridImageColumn Exception

Hello,

I'm trying to export a datagrid to a pdf that contains GridImageColumn mapped to a ImageSource property on a record.  When I attempt to export I receive the following exception.

Object reference not set to an instance of an object.
at Syncfusion.SfDataGrid.XForms.Exporting.ExportingHelper.GetImagePath (Xamarin.Forms.StreamImageSource imageSource) [0x00050] in <633664e6b4d14452a8c06ce5ecaf0124>:0 
  at Syncfusion.SfDataGrid.XForms.Exporting.DataGridPdfExportingController.ExportCellValue (Syncfusion.SfDataGrid.XForms.SfDataGrid dataGrid, Syncfusion.Data.RecordEntry record, Syncfusion.SfDataGrid.XForms.GridColumn column, Syncfusion.Pdf.Grid.PdfGridCell pdfCell, Syncfusion.SfDataGrid.XForms.Exporting.DataGridPdfExportOption exportOption, System.Object pagedRecord) [0x00220] in <633664e6b4d14452a8c06ce5ecaf0124>:0 

I've attached a sample showing the exception. Is there a workaround for this issue?

Thanks!


Attachment: DataGrithWithImagePdfExport_83069249.zip

10 Replies

SP Subburaj Pandian Veluchamy Syncfusion Team July 25, 2019 01:18 PM UTC

Hi Eric Hamrick, 
 
Thank you for contacting Syncfusion support.

Based on your provided sample, we have analyzed that you are setting the image source like a stream, but you didn’t have to do those process and we have already handled that converting image source into stream source in our source-level itself. Instead of providing the stream source, you can set the image source directly by “FromResource” or “FromFile” to overcome from this issue. You can directly provide the image resource as mentioned in below code snippet.
 
  
Please refer the code snippet for your reference, 
  
[C#] 
  
var source = ImageSource.FromResource("DataGrithWithImagePdfExport.Resources.genericface.jpg"); 
Persons.Add(new Person() { Name = "John Smith", Photo = source }); 
  
 
 
We hope this helps. Please let us know, if you would require any further assistance. 
 
Regards,
Subburaj Pandian V 



EH Eric Hamrick July 25, 2019 08:52 PM UTC

Hello,


Thank you for the reply but unfortunately it doesn't address my particular use.   This was a sample created based on what I saw in my full app which is retrieving photos as a  byte array data  from the database so I was trying to simulate starting with a byte array. Do you know why it receives an exception when starting with a  byte array??  I'm not  able to use FromResource or FromFile for creating the imagesource in my full application.

Eric


BS Balasubramani Sundaram Syncfusion Team July 30, 2019 06:57 PM UTC

Hi Eric Hamrick 
 
Thank you for the update. 
  
Currently, we are validating the reported issue “Datagrid Export to PDF with GridImageColumn Exception”. We will validate and update you further details on (July 31, 2019). We appreciate your patience until then. 
 
Regards,
Balasubramani Sundaram.
 



BS Balasubramani Sundaram Syncfusion Team August 1, 2019 02:00 PM UTC

Hi Eric Hamrick 
 
Thank you for your patience 
  
We have done a deep analysis of the reported issue “Datagrid Export to PDF with GridImageColumn Exception”. In Xamarin.Forms when we are using the “FromFile” or “FromResource”, in backend Xamarin.Forms.ImageSource will return a StreamImageSource type which will create a new Xamarin.Forms.ImageSource from the specified resource in the specified source assembly, when come to our case by providing the source as steam, in backend as the same it will return the same StreamImageSource type with “UnManagedImageStream” from that we weren’t able to retrieve the image data and if we convert into a System.IO.Stream it's providing with close state. So, we are trying hard to provide the solution for this, we also share this issue on stack overflow as well we asked to Xamarin. Forms Teams once we get the solution we will update to you. We appreciate your patience until then.


Regards,
Balasubramani Sundaram. 


EH Eric Hamrick August 15, 2019 02:56 PM UTC

https://github.com/xamarin/Xamarin.Forms/issues/7026

I notice that the issue above is closed.  Its not clear from the last comment whether this will lead to a solution for using ImageSource from a byte array?


Thanks!

Eric


SP Subburaj Pandian Veluchamy Syncfusion Team August 19, 2019 01:26 PM UTC

Hi Eric Hamrick, 
  
Thank you for the update. 
  
We have updated the necessary details about the issue in comments with the same GitHub report. 
  
We are following the report, we will update you the details, once we get the correct solution from Xamarin Team. We appreciate your patience until then. 
 
Regards,
Subburaj Pandian V  
 



EH Eric Hamrick September 26, 2019 08:51 PM UTC

I've not seen any update on this item for a while.  There is no workaround available?  Maybe you have a suggestion how how to modify the Xamarin Forms source code to fix this issue?

Thank you,

Eric


BS Balasubramani Sundaram Syncfusion Team September 29, 2019 07:26 PM UTC

Hi Eric,  
 
Thanks for the update.   
 
We regret the inconvenience caused. We couldn’t have the workaround for your requirement, and we are still waiting for the valid solution from the Xamarin team. 
 
We appreciate your patience until then. 
 
Regards,  
Balasubramani Sundaram. 



EH Eric Hamrick October 2, 2019 04:56 AM UTC

Since it looks Xamarin team closed that item the only choice is to do a pull request to fix it or a custom xamarin forms build.  In the mean time the workaround is just to export all the photos from the database to storage when I need to print and then use imagesoure.fromfile which seems to work ok.



BS Balasubramani Sundaram Syncfusion Team October 4, 2019 01:21 AM UTC

 
Hi Erik,  
 
Thanks for the update.   
 
You can use that workaround of saving the image and retrieve the images by using “ImageSource.FormFile()”.  
 
Regards, 
Balasubramani Sundaram. 


Loader.
Live Chat Icon For mobile
Up arrow icon