I am using the 2011 Reporting CTP to try anb write code that will take a XamWebChart instance, stick it in a report, then print it. This is all in SL4 and, ideally, no XAML would be involved. I cannot seem to find any useful documentation or samples regarding the relevant classes (Report, Section).
This was a trivial task with Telerik's libraries, but I have not been able to determine how this can be accomplished using Infragistics' libraries.
Andres:
I was able to build an IImageEncoder implementation around the Stegman PngEncoder class you referred to and, now that I'm actually digging in the right mine, figure out how to use the Word and Excel document classes to get exports to those file formats. Except for the lack of XPS support, I've got all my target formats covered.
That said, PPT (PowerPoint) would be really nice; does Infragistics have anything for that?
Hi,
Yes, the PngEncoder and XPS are not working in the bits you have. We are not using PNG to encode our images, and we found some issues with XPS so it will probably not ship in Reporting either.
The .AddImage class receives and Image instance, so you could try finding any other encoding code in the web and use it to convert the WriteableBitmap into an Image. If you google for 'Joe Stegman’s PngEncoder' you'll find some code.
You basically had achieved all what you could with the bits you have.
Regards,
Andres
Oops. You need this routine, too:private static void ExportDocument(XamWebChart analytic, string defaultExt, string defaultFilter, FileFormat fileFormat){ var dialog = new SaveFileDialog { DefaultExt = defaultExt, Filter = defaultFilter }; if (dialog.ShowDialog() != true) return; var document = MakeReportFromAnalytic(analytic, 500, 700); using (var stream = dialog.OpenFile()) { document.Publish(stream, fileFormat); }}
Thank you. With that last bit of information I have been able to achieve at least some success. I now have two routines: one that exports a XamWebChart to an image of some format, and one that attempts to export it as a document of some format.In the case of images, the only formats I could find Infragistics encoders for were JPEG and PNG. In the case of documents, the only formats that I could find support for were PDF and XPS.
In my tests, the JPEG and PDF paths work; PNG and XPS fail. The PNG path fails with a "not implemented" exception inside the IImageEncoder.Encode() method, and the XPS path generates a document, but the XPS Viewer cannot display the resulting page.
My code is as follows:private static Report MakeReportFromAnalytic(XamWebChart analytic, int height, int width){ var report = new Report(); var section = report.AddSection(); var bitmap = new WriteableBitmap(analytic, null); using (var encodedBitmap = new MemoryStream()) { new JpegImageEncoder().Encode(bitmap, new List<EncodingProperty> {new gQualityProperty{Quality = 100}}, encodedBitmap); var nativeImage = System.Drawing.Image.FromStream(encodedBitmap); var infragisticsImage = new Image(nativeImage, false); section.AddImage(infragisticsImage); } return report;}private static void ExportImage(XamWebChart analytic, string defaultExt, string defaultFilter, IImageEncoder encoder, IList<EncodingProperty> encodingProperties){ var dialog = new SaveFileDialog { DefaultExt = defaultExt, Filter = defaultFilter }; if (dialog.ShowDialog() != true) return; using (var stream = dialog.OpenFile()) { var bitmap = new WriteableBitmap(analytic, null); using (var encodedBitmap = new MemoryStream()) { encoder.Encode(bitmap, encodingProperties, encodedBitmap); var byteArray = encodedBitmap.ToArray();
stream.Write(byteArray, 0, byteArray.Length); } }}// These two invocations work...private static void ExportAsPdf(XamWebChart analytic){ ExportDocument(analytic, @"*.pdf", @"Adobe PDF Document (*.pdf)|*.pdf", FileFormat.PDF);}private static void ExportAsJpg(XamWebChart analytic){ ExportImage(analytic, @"*.jpg", @"JPEG Image (*.jpg)|*.jpg", new JpegImageEncoder(), new List<EncodingProperty> { new JpegQualityProperty { Quality = 100 } } );}// These two fail as detailed aboveprivate static void ExportAsXps(XamWebChart analytic){ ExportDocument(analytic, @"*.xps", @"Microsoft XPS Document (*.xps)|*.xps", FileFormat.XPS);}private static void ExportAsPng(XamWebChart analytic){ ExportImage(analytic, @"*.png", @"PNG Image (*.png)|*.png", new PngImageEncoder(), new List<EncodingProperty>());}I see no obvious reason for this, particularly for the "not implemented" exception. Beyond that, is there support (using these mechanisms) for any other document or image types beyond the ones I have listed above?
They are in C:\Program Files (x86)\Infragistics\NetAdvantage 2011.2\Reporting\Bin\InfragisticsSL4.Documents.Reports.v11.2.dll
I apologize for not being clear ;), I thought you were already using it.