Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we show .rtf or .doc as flowdocument in WPF?

It is for the help section of the application. I am thinking to put flowdocumentReader to show the help document. But is it possible to show .rtf or any .doc to show in Flowdocument.Or is it neccesary to create a flow document in Xaml. Please help.

Thanks,

like image 529
Ershad Avatar asked Oct 26 '09 04:10

Ershad


People also ask

What is FlowDocument in WPF?

Flow documents are designed to optimize viewing and readability. Rather than being set to one predefined layout, flow documents dynamically adjust and reflow their content based on run-time variables such as window size, device resolution, and optional user preferences.


1 Answers

Something on these lines will do the job for you where documentPath is your rtf file path:

FileStream fileStream = File.Open(documentPath, FileMode.Open, FileAccess.Read, FileShare.Read);

FlowDocument flowDocument = new FlowDocument();

TextRange textRange = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd);

textRange.Load(fileStream , DataFormats.Rtf);

Do add the error checking code though.

like image 76
Yogesh Avatar answered Oct 04 '22 01:10

Yogesh