I save the WPF FlowDocument to the file system using this code and the file name with the xps extension:
// Save FlowDocument to file system as XPS document using (var fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { var textRange = new TextRange(m_Text.ContentStart, m_Text.ContentEnd); textRange.Save(fs, DataFormats.XamlPackage); }
My application can reload the document using this code:
// Load file using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { m_Text = new FlowDocument(); var textRange = new TextRange(m_Text.ContentStart, m_Text.ContentEnd); textRange.Load(fs, DataFormats.XamlPackage); }
However, the XPS Viewer that ships with Windows 7 cannot open files. Saved XPS files display the XPS icon, but when you double-click it, the XPS viewer cannot open it. The error message reads: "XPS Viewer cannot open this document."
Any idea what I need to do for my XPS document to make it available to view the XPS Viewer? Thank you for your help.
wpf xps flowdocument
David veeneman
source share