Hi,
I am trying to create a report in our Silverlight application and add an image to that report but for some reason, when ever I create the Image (Infragistics.Documents.Reports.Graphics) object, my Data, Width and Height are always 0. even though I pass in a byte array with data in it.
The image I am trying to add to the report is an image of the xamWebChart.
Here's the code:
Report report = new Report(); ISection reportSection = report.AddSection(); IBand reportBand = reportSection.AddBand();//this would have some content in it.XamWebChart chart = new XamWebChart(); WriteableBitmap bitmap = new WriteableBitmap(chart, null); byte[] imageByte = bitmap.ToByteArray(); using (MemoryStream stream = new MemoryStream(imageByte)) { Image image = new Image(System.Drawing.Image.FromStream(stream), true); var reportImage = reportBand.AddImage(image); reportImage.KeepRatio = true; }
The .ToByteArray() method basically converts that WriteableBitmap into a byte[]:
public static byte[] ToByteArray(this WriteableBitmap bmp) { int[] p = bmp.Pixels; int len = p.Length << 2; byte[] result = new byte[len]; Buffer.BlockCopy(p, 0, result, 0, len); return result; }
Is there a proper way to add an image to the report in silverlight? Thanks!
The Infragistics.Documents is only shipped by the Reporting product to be used internally, as part of the PDF-exporting functionality, it’s not meant to be used directly.
You can create a report that includes a chart, and then export it to PDF. In order to export it, you need to include a XamReportViewer on your page and then use the Export method, for instance:
var dialog = new SaveFileDialog();
var result = dialog.ShowDialog();
if (result.HasValue && result.Value)
{
var stream = dialog.OpenFile();
// ReportViewer is the XamReportViewer instance that was inserted on the page
ReportViewer.Export(stream, "PDF");
ReportViewer.ExportCompleted += ExportCompleted;
}
Since the export process is asynchronous, you also need to close the stream once export is completed:
private void ExportCompleted(object sender, ExportCompletedEventArgs e)
ReportViewer.ExportCompleted -= ExportCompleted;
e.Stream.Close();
If you don’t want to show the Report Viewer in the page, you can set the opacity to zero, as it needs to be present in the Silverlight visual tree.
Regards,
Andres
Andres,
By creating a report, do you mean using your .igr (report templates)? I considered creating a report template. However, I am having troubles with the DataSource for the template because we perform a RIA service query, process that data on the client side and then display it to the user using a customised XamWebChart.
How would I add a custom control into that template and set the datacontext of the table and the chart in our report to bind to different parts of the ViewModel (instead of using that Object DataSource wizard where it makes you choose a method to call)?
I hope that was clear, if it wasn't. I can try to clarify any unknowns.
Thanks!
Connie