BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
The Text written into the Rich Text Box is stored in html, rft as well as plain text in our db.
Since the Text Box does not offer the option to get the rtf string directly i am converting the html value i get from the Text Box using DocIO.
So far so good, in most test cases the html gets converted to rtf without issue. If shitf + enter is used for a line break tough the html is considered invalid by DocIO.
The report.DescritionHtml property is directly bound with @bind-Value so there is no changes made to it that could invalide the structure.
In my test case the html resulting from the content in the Text Box was the following:
<p>Test Content before shift enter.<br>Test Content after shift enter.</p>
Trying to convert this html value resulted in a error in this line:
document = new WordDocument(stream, FormatType.Html, XHTMLValidationType.None);
The error was the following:
System.NotSupportetException | DocIO support only welformatted xhtml Details:The 'br' start tag on line 1 position 77 does not match the end tag of 'p'. Line 1, position 113.
Is this a mistake on my side? Do i need to somehow support badly structured html? Is my conversion methode badly implemented?
Hi Richard,
To solve your problem, we suggest using the XmlConversion and XhtmlConversion classes to convert the HTML to well-formed XHTML before passing it to the DocIO library.
public WordDocument GetDocument(string htmlText) { WordDocument document = null; MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream, System.Text.Encoding.Default); htmlText = htmlText.Replace("\"", "'"); XmlConversion XmlText = new XmlConversion(htmlText); XhtmlConversion XhtmlText = new XhtmlConversion(XmlText); writer.Write(XhtmlText.ToString()); writer.Flush(); stream.Position = 0; document = new WordDocument(stream, FormatType.Html, XHTMLValidationType.None); return document; } |
We hope this fix will resolve your issue. If the issue still persists, kindly revert back to us.
Regards,
Vinothkumar
Hi Vinothkumar,
where can i find the
XmlConversion
and XhtmlConversion classes
?
Regards
Joachim
Hi Joachim,
You can use Syncfusion.EJ.Export the namespace in your application to use the XmlConversion classes. I have attached the Nuget package screenshot for your reference.
Regards,
Vinothkumar
Hi
Vinothkumar,
thank you for the information.
But now the following line
XhtmlConversion XhtmlText = new XhtmlConversion(XmlText);
leads to the error message:
Unable to cast object of type 'System.Xml.XmlText' to type 'System.Xml.XmlElement'.
I'm using:
"Syncfusion.EJ.Export" Version="20.4.0.44"
"Syncfusion.Blazor" Version="21.1.35"
Thanks in advance !
Regards
Joachim
Hi Joachim,
We suspect that the reported issue of "Html generated by the Rich Text Box is invalid" is occurred due to unformatted HTML while converted to rtf using DocIO. That means html tags must open and close properly, so here we have replaced the <br> with <br/> from the retrieved HTML strings. You can convert them by using the following code:
public WordDocument GetDocument(string htmlText) { htmlText = htmlText.Replace("\"", "'").Replace("<br>","<br/>"); } |
If you are still facing an error, could you please share a runnable sample so that we can replicate your problem at our end?
for what's it's worth: i had the same issue and it was because I has a space between br and / in the code.
NOT OK: <br />
OK: <br/>
Rgds
Frederik
Hi Frederik,
Thanks for an update,
From your query, we suspect that your issue has been resolved on you own.
If you have any further queries, please get back to us.