Convert FlowDocument To Rtf

Stimulsoft Reports.WPF discussion
Post Reply
mosoul
Posts: 14
Joined: Fri Jan 25, 2013 9:26 am
Location: France

Convert FlowDocument To Rtf

Post by mosoul »

Hello,

In our base we save FlowDocument as Text. And i have to display it on Report.
I found this Topic http://forum.stimulsoft.com/viewtopic.p ... ent#p12393.
So i've code this on GetValueEvent :

Code: Select all

byte[] byteArray = System.Text.Encoding.Default.GetBytes(ListeDesMouvementsCaisse.Commentaire);
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);

string str = Stimulsoft.Report.Wpf.StiRtfHelper.ConvertFlowDocumentToRtf(stream); 
e.Value = System.Xml.XmlConvert.EncodeName(StiRichText.PackRtf(str));
But when i made an preview of my report in the designer i have this Report rendering message:
Expression in Text property of 'RichText1' can't be evaluated! Root element is missing.
My FlowDocument is valid because i can display it in my application on a WPF RichTextBox with a string to FlowDocument convert :

Code: Select all

var flowDocument = new FlowDocument();
var valeur = myStringOfFlowDocument;

if (!string.IsNullOrEmpty(valeur))
{
      var stringReader = new StringReader(valeur);
      var xmlTextReader = new XmlTextReader(stringReader);
      flowDocument = (FlowDocument)XamlReader.Load(xmlTextReader);
}
Can you hel me?

Regards,
Morgan SOULLEZ
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Convert FlowDocument To Rtf

Post by HighAley »

Hello, Morgan.

Could you send us sample project which reproduces the issue for analysis?

Thank you.
mosoul
Posts: 14
Joined: Fri Jan 25, 2013 9:26 am
Location: France

Re: Convert FlowDocument To Rtf

Post by mosoul »

Hello,

You can find the Report on attachment, and an example of Data in my DataBase.

Thanks,
Morgan
Attachments
ListeMouvements.mrt
Report file
(22.14 KiB) Downloaded 503 times
DataExample.csv
Data example (extract from DataBase)
(2.3 KiB) Downloaded 524 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Convert FlowDocument To Rtf

Post by HighAley »

Hello.

There is Null value in your data in the first report.
Please, try to check it before trying to convert to RTF.

Thank you.
mosoul
Posts: 14
Joined: Fri Jan 25, 2013 9:26 am
Location: France

Re: Convert FlowDocument To Rtf

Post by mosoul »

Hi,

Thanks for your reply.

I Check it and convert only no null value, but my RichText does not display value...

Regards,
Morgan
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Convert FlowDocument To Rtf

Post by HighAley »

Hello.

Do you get any error?
Could you send new report to us for analysis.

Thank you.
mosoul
Posts: 14
Joined: Fri Jan 25, 2013 9:26 am
Location: France

Re: Convert FlowDocument To Rtf

Post by mosoul »

Hi,

No i don't have any error...

Regards,
Morgan
Attachments
ListeMouvements.mrt
Report
(22.3 KiB) Downloaded 562 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Convert FlowDocument To Rtf

Post by HighAley »

Hello.

We use next code:

Code: Select all

byte[] byteArray = System.Text.Encoding.Default.GetBytes(ListeDesMouvementsCaisse.Commentaire);
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
FlowDocument doc = new FlowDocument();
TextRange documentTextRange2 = new TextRange(doc.ContentStart, doc.ContentEnd);
documentTextRange2.Load(stream, System.Windows.DataFormats.Xaml);
This code load text from FlowDocument. But we don't see any text in the Debug mode.

Thank you.
mosoul
Posts: 14
Joined: Fri Jan 25, 2013 9:26 am
Location: France

Re: Convert FlowDocument To Rtf

Post by mosoul »

Hi,

I've resolved my problem !

With this source code :

Code: Select all

if (!string.IsNullOrEmpty(ListeDesMouvementsCaisse.Commentaire))
{
      var flowDocument = new System.Windows.Documents.FlowDocument();
      var stringReader = new System.IO.StringReader(ListeDesMouvementsCaisse.Commentaire);
      var xmlTextReader = new System.Xml.XmlTextReader(stringReader);
      flowDocument = (System.Windows.Documents.FlowDocument)System.Windows.Markup.XamlReader.Load(xmlTextReader);
      var tr = new System.Windows.Documents.TextRange(flowDocument.ContentStart, flowDocument.ContentEnd);
      var stream = new System.IO.MemoryStream();
      tr.Save(stream, System.Windows.DataFormats.Xaml);
      var str = Stimulsoft.Report.Wpf.StiRtfHelper.ConvertFlowDocumentToRtf(stream);
      e.Value = System.Xml.XmlConvert.EncodeName(Stimulsoft.Report.Components.StiRichText.PackRtf(str));
}
And with this ReferencedAssemblies :

Code: Select all

System.Dll
System.Drawing.Dll
System.Windows.Forms.Dll
System.Data.Dll
System.Xaml.dll
System.Xml.Dll
PresentationCore.dll
PresentationFramework.dll
WindowsBase.dll
Stimulsoft.Controls.Dll
Stimulsoft.Base.Dll
Stimulsoft.Report.Dll
Stimulsoft.Report.Wpf.dll
Regards,
Morgan
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Convert FlowDocument To Rtf

Post by HighAley »

Hello.

Thank you for solution.
Do not hesitate to contact us in future if you have any problems else.

Thank you.
Post Reply