I have a report object which I can generate PDF by calling report.Publish(fileName, fileType) method and it works fine. However I need another method where I can generate stream bytes[] or the object. I tried using following code but it shows error because Report object is not serializable. My code:
//convert report object to bytesbyte[] bytes = ObjectToByteArray(report);
private static byte[] ObjectToByteArray(object obj) { if (obj == null) return null; BinaryFormatter bf = new BinaryFormatter(); using (MemoryStream ms = new MemoryStream()) { bf.Serialize(ms, obj);//ERROR comes here return ms.ToArray(); } }
any help is appreciated.
Hello sarojanand@gmail.com,
The Infragistics.Documents.Reports.Report Report class is not serializable indeed.
A possible workaround would be creating your custom serializable class that inherits from Infragistics.Documents.Reports.Report Report class or use a third-party serialization library.
If the workaround options do not help, could you please provide some additional information about what you are trying to achieve with the method that generates stream bytes and I will try to find another solution to this issue.
Basically I am trying to send this report to a remote printer via API.
This printer is connected on a remote Linux server which accepts byte[]/streams and then it convert them to PDF and then print it. For this reason I am trying to convert it to steam bytes.
Another issue: when I generate PDF using publish method. It opens fine on my local PC but same PDF if I try to open on remote Linux server for printing, it not able to read it. Dont know what could be the reason.