Good Day
I'm using VS 2005 to create a WPF based training program. I would very much like to display the course materials in a FlowDocumentReader that enable the user to dynamically choose between various viewing modes. How can I use Word 2007 to create the documents and then display them as a FlowDocument?
Any help would be great!
Hi Mike,
I am not entirely sure, but I believe you need to save the document as XPS and then open it using the XpsDocument class of the packaging API.
Hope it helps!
By design, Open XML (docx here) is a kind of document-to-be-edited while XPS is final, optimized for printing one (like PDF). So, if your app is switched between viewing and editing, editing part would be hard to implement.
If you need only to render once created document, you can save docx file as XPS from Word app or use XpsDocumentWriter
hey,
u can create a XML file with Flowdocument and then read the same using filestream to create a flowdoc. and the assign it to the richtextbox
eg
FileStream fs = new FileStream("Resources\\Word.xml", FileMode.Open);FlowDocument fd = XamlReader.Load(fs) as FlowDocument;fs.Close();richtextboxBold.Document = fd;
hope this helps.
Mahesh
Hi Mahesh,
this does not work at all for me. Are you sure this is a viable option? The file we are opening is not XAML, it is WordProcessingML.
Displaying an XPS document is easy though. Just add a DocumentViewer to your XAML form, and use two lines of code to display your document:
XpsDocument doc = new XpsDocument("MyDoc.xps", FileAccess.Read);docViewer1.Document = doc.GetFixedDocumentSequence();
So my best guess is to use Word to save your document as an XPS file, next use that file to display. You can of course write an XSLT to convert the DOCX to XPS, but I dunno how hard that is going to be.