Display FixedPage Content on Bitmap

I have the following code, taken from http://www.codeplex.com/XPS2Image/ , which, in turn, was taken from a discussion on the Microsoft Developer Network developer forums.

int[] pages = new int[] { 0, 1, 2, 3, 4 }; XpsDocument xpsDoc = new XpsDocument(@"c:\tmp\sample.xps", System.IO.FileAccess.Read); FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence(); // You can get the total page count from docSeq.PageCount foreach (int pageNum in pages) { DocumentPaginator paginator = docSeq.DocumentPaginator; DocumentPage docPage = paginator.GetPage(pageNum); BitmapImage bitmap = new BitmapImage(); RenderTargetBitmap renderTarget = new RenderTargetBitmap((int)docPage.Size.Width, (int)docPage.Size.Height, 96, // WPF (Avalon) units are 96dpi based 96, System.Windows.Media.PixelFormats.Pbgra32); renderTarget.Render(docPage.Visual); PngBitmapEncoder encoder = new PngBitmapEncoder(); // Choose type here ie: JpegBitmapEncoder, etc encoder.Frames.Add(BitmapFrame.Create(renderTarget)); FileStream pageOutStream = new FileStream("c:\\tmp\\xpsdocPage" + pageNum + ".jpg", FileMode.Create, FileAccess.Write); encoder.Save(pageOutStream); pageOutStream.Close(); } 

This works fine, except that the deleted ResourceDictionaries used in FixedPage are not displayed. Any ideas?

+4
source share

All Articles