How to use FlowDucument-property

Stimulsoft Reports.WPF discussion
Post Reply
stehwn
Posts: 22
Joined: Wed Jul 08, 2009 8:20 am

How to use FlowDucument-property

Post by stehwn »

Hi,

my businessobject has text-properties of type FlowDocument (can be converted to rtf).
Is it possible to use the formatted FlowDocument for report-creation?


Best Regards
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

How to use FlowDucument-property

Post by Jan »

Hello,

We have added new static method which can help you load FlowDocument to richtext. New method will be available in prerelease build from 26 April. Please use following code for GetValueEvent of richtext component:

Code: Select all

System.IO.Stream stream = new System.IO.FileStream("d:\\test.xaml", System.IO.FileMode.Open);
string str = Stimulsoft.Report.Wpf.StiRtfHelper.ConvertFlowDocumentToRtf(stream);
e.Value = System.Xml.XmlConvert.EncodeName(StiRichText.PackRtf(str));
You need add reference to Stimulsoft.Report.Wpf.dll in ReferencedAssemblies property of report. You can do this in report designer. Also you can implement method ConvertFlowDocumentToRtf in report code. Here is source code of this method:

Code: Select all

public static string ConvertFlowDocumentToRtf(Stream stream)
        {
            RichTextBox richTextBox = new RichTextBox();

            TextRange documentTextRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
            documentTextRange.Load(stream, DataFormats.Xaml);

            MemoryStream tempStream = new MemoryStream();
            documentTextRange.Save(tempStream, DataFormats.Rtf);
            return System.Text.Encoding.Default.GetString(tempStream.GetBuffer());

        }
Thank you.
stehwn
Posts: 22
Joined: Wed Jul 08, 2009 8:20 am

How to use FlowDucument-property

Post by stehwn »

Thank you!

I'll try that.

Best Regards
Andrew
Posts: 4107
Joined: Fri Jun 09, 2006 3:58 am

How to use FlowDucument-property

Post by Andrew »

Hello,

Let us know about the result.

Thank you.
stehwn
Posts: 22
Joined: Wed Jul 08, 2009 8:20 am

How to use FlowDucument-property

Post by stehwn »

Hi,

I tested it and it works without any problems!

I let my businessobject do the converting, so I dont have to add references in the designer.


Best Regards
Steffen
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

How to use FlowDucument-property

Post by Jan »

Hello Steffen,

Glad to help you.

Thank you.
Post Reply