Page 1 of 1

Convert FlowDocument To Rtf

Posted: Wed Aug 21, 2013 10:26 am
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

Re: Convert FlowDocument To Rtf

Posted: Thu Aug 22, 2013 9:30 am
by HighAley
Hello, Morgan.

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

Thank you.

Re: Convert FlowDocument To Rtf

Posted: Thu Aug 22, 2013 12:55 pm
by mosoul
Hello,

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

Thanks,
Morgan

Re: Convert FlowDocument To Rtf

Posted: Fri Aug 23, 2013 1:03 pm
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.

Re: Convert FlowDocument To Rtf

Posted: Fri Aug 23, 2013 1:26 pm
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

Re: Convert FlowDocument To Rtf

Posted: Fri Aug 23, 2013 2:24 pm
by HighAley
Hello.

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

Thank you.

Re: Convert FlowDocument To Rtf

Posted: Mon Aug 26, 2013 7:12 am
by mosoul
Hi,

No i don't have any error...

Regards,
Morgan

Re: Convert FlowDocument To Rtf

Posted: Mon Aug 26, 2013 12:57 pm
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.

Re: Convert FlowDocument To Rtf

Posted: Tue Aug 27, 2013 8:52 am
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

Re: Convert FlowDocument To Rtf

Posted: Tue Aug 27, 2013 10:51 am
by HighAley
Hello.

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

Thank you.