I am trying to write an image to a word document using WordDocumentWriter.
I took the code from the samples browser and baseline and added the following lines of code to write an image to word document. I get the below error when AddInlinePicture method is executed. The
docWriter.StartParagraph(); // Add image docWriter.AddInlinePicture(LoadImage(@"/SilverlightApplication1;component/a.png")); docWriter.AddNewLine(); docWriter.EndParagraph();
LoadImage method below. A valid bitmapimage object is returned by this method.
public BitmapImage LoadImage(string relativeUriString) { // Get the image stream at the specified URI that // is relative to the application package root. Uri uri = new Uri(relativeUriString, UriKind.Relative); StreamResourceInfo sri = Application.GetResourceStream(uri); // Convert the stream to an Image object. BitmapImage bi = new BitmapImage(); bi.SetSource(sri.Stream); Image img = new Image(); img.Source = bi; return bi; }
Error message on calling AddInlinePicture method:
Hello,
Thank you for your post. I have been looking into it and I gave created a sample project for you with the functionality you want. Basically you need to set the WordDocumentWriter’s ImageEncoder Property to an object that implements IImageEncoder interface. Our Reporting team has created such encoders for .png and .jpg/.jpeg files, but before version 12.1, they weren’t exposed into Silverlight product, only in our Reporting’s Imaging assembly. The sample I attached uses 12.1.
Hope this helps you.