Welcome to OpenXML Developer Sign in | Join | Help

Docx into WPF FlowDocument

Last post 08-29-2006, 2:33 AM by Wouterv. 4 replies.
Sort Posts: Previous Next
  •  07-16-2006, 5:28 PM 363

    Docx into WPF FlowDocument

    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!

     

  •  08-01-2006, 2:25 AM 418 in reply to 363

    Re: Docx into WPF FlowDocument

    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!


    Wouter van Vugt
  •  08-13-2006, 6:51 PM 495 in reply to 363

    Re: Docx into WPF FlowDocument

    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

  •  08-28-2006, 5:07 PM 579 in reply to 363

    Re: Docx into WPF FlowDocument

    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

  •  08-29-2006, 2:33 AM 584 in reply to 579

    Re: Docx into WPF FlowDocument

    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.

    Hope it helps!


    Wouter van Vugt
View as RSS news feed in XML