Hi,
I am working with creating WPF Flowdocuments from windows that are dynamically loaded from xaml that is stored in a database.
I need to take advantage of the pagination of an xps file format, and use a documentviewer control to allow for printing.
I have everything working with the exception of the saving of the image data from the flowdocument.
The xps converter throws a "property urisource or property streamsource must be set " error.
The generated xaml code looks like this...
<BlockUIContainer><Image><Image.Source><FormatConvertedBitmap DestinationFormat="Bgr32" DestinationPalette="{x:Null}" AlphaThreshold="0"><FormatConvertedBitmap.Source><BitmapImage BaseUri="{x:Null}" /></FormatConvertedBitmap.Source></FormatConvertedBitmap></Image.Source></Image></BlockUIContainer>
My code to generate the document is as follows....
Dim pFlDoc As New FlowDocument Dim pStream As New MemoryStream("Database Call Here to get image") Dim pCtl As New Image Dim pImage As New BitmapImage() pImage.BeginInit() pImage.StreamSource = pStream pImage.EndInit() pCtl.Source = pImage ' get image size from xml tag attribute in source xmlelement Dim pS As Size pS.Height = pXMLTag.GetAttribute("height") pS.Width = pXMLTag.GetAttribute("width") pCtl.RenderSize = pS Dim pBlock As New BlockUIContainer pBlock.Child = pCtl pFlDoc.Blocks.Add(pBlock)
The image will view in a flowdocumentpageviewer, but I need to print the document and I am using code from a forum post to export the document to xps and then load it into a documentviewer, which then allows printing by default.
I can save the image to disk and then re-load it, but I would rather keep disk io to a minimum and perform all operations in memory.
Is there any code examples that would help me render my image into the xaml? I suspect that I need to do some encoding but I'm not able to find any examples that would assist.
Thanks.