- Home
- Forum
- Xamarin.Forms
- Error export to Doc
Error export to Doc
Hello, I am trying to generate a word from the information that a SfRichTextEditor contains, but doing so throws me this error.The component string has two base64 images along with text and format.The 'img' start tag on line 1 position 65 does not match the end tag of 'p'. Line 1, position 32412. ---> System.Xml.XmlException: The 'img' start tag on line 1 position 65 does not match the end tag of 'p'. Line 1, position 32412.
SIGN IN To post a reply.
3 Replies
1 reply marked as answer
SB
Suriya Balamurugan
Syncfusion Team
July 28, 2020 06:26 AM UTC
Hi Rafael,
Thank you for contacting Syncfusion support.
Essential DocIO supports only well formatted HTML. We use XmlReader for parsing the content of input HTML. So, the input HTML should meet the XML standard (have proper open and close tags).
From given details, we suspect, the html string is not having a proper end tag for <img> tag. So, the exception occurs at your end. Therefore, we suggest you add proper </img> end tag for <img> start tag and then use that well formatted HTML in DocIO.
Please refer our UG documentation to know more about HTML to Word conversion:
https://help.syncfusion.com/file-formats/docio/html
Please let us know if you have any other questions.
Regards,
Suriya Balamurugan.
Thank you for contacting Syncfusion support.
Essential DocIO supports only well formatted HTML. We use XmlReader for parsing the content of input HTML. So, the input HTML should meet the XML standard (have proper open and close tags).
From given details, we suspect, the html string is not having a proper end tag for <img> tag. So, the exception occurs at your end. Therefore, we suggest you add proper </img> end tag for <img> start tag and then use that well formatted HTML in DocIO.
Please refer our UG documentation to know more about HTML to Word conversion:
https://help.syncfusion.com/file-formats/docio/html
Please let us know if you have any other questions.
Regards,
Suriya Balamurugan.
RO
Rafael Ortiz
July 28, 2020 07:25 AM UTC
Hello, the html string is retrieved from the HtmlText method of the SfRichTextEditor component, I attach it as it is collected.
htmlstring = I attach it as it is collected.
using (WordDocument document = new WordDocument())
{
byte[] byteArray = Encoding.ASCII.GetBytes(htmlstring);
//Loads or opens an existing Word document from stream
Stream inputStream = new MemoryStream(byteArray);
//Loads or opens an existing Word document through Open method of WordDocument class
document.Open(inputStream, FormatType.Html);
//Creates an instance of memory stream
MemoryStream stream = new MemoryStream();
//Saves the document to stream
document.Save(stream, FormatType.Docx);
//Closes the document
document.Close();
//Save the stream as a file in the device and invoke it for viewing
Xamarin.Forms.DependencyService.Get<ISaveExport>().Save("HTMLtoWord.docx", "application/msword", stream);
{
byte[] byteArray = Encoding.ASCII.GetBytes(htmlstring);
//Loads or opens an existing Word document from stream
Stream inputStream = new MemoryStream(byteArray);
//Loads or opens an existing Word document through Open method of WordDocument class
document.Open(inputStream, FormatType.Html);
//Creates an instance of memory stream
MemoryStream stream = new MemoryStream();
//Saves the document to stream
document.Save(stream, FormatType.Docx);
//Closes the document
document.Close();
//Save the stream as a file in the device and invoke it for viewing
Xamarin.Forms.DependencyService.Get<ISaveExport>().Save("HTMLtoWord.docx", "application/msword", stream);
Attachment: HTML_df767493.zip
SB
Suriya Balamurugan
Syncfusion Team
July 29, 2020 09:12 AM UTC
Hi Rafael,
Thank you for your update.
We can reproduce the reported problem with “DocIO support only welformatted xhtml” exception at our end. We have found your input html string is not well formatted. Essential DocIO supports only well formatted.
On analyzing further, we found, the given html string is not having a proper end tag. So, we suggest you to add proper end tags for each start tag and then use that well formatted HTML in DocIO.
We have modified the given HTML string by adding the proper end tags for <img> and <br> tags to resolve the reported problem. It can be downloaded from the below link:
https://www.syncfusion.com/downloads/support/forum/156427/ze/Modified_HTML-2096577764
Please let us know if you have any other questions.
Regards,
Suriya Balamurugan.
Thank you for your update.
We can reproduce the reported problem with “DocIO support only welformatted xhtml” exception at our end. We have found your input html string is not well formatted. Essential DocIO supports only well formatted.
On analyzing further, we found, the given html string is not having a proper end tag. So, we suggest you to add proper end tags for each start tag and then use that well formatted HTML in DocIO.
We have modified the given HTML string by adding the proper end tags for <img> and <br> tags to resolve the reported problem. It can be downloaded from the below link:
https://www.syncfusion.com/downloads/support/forum/156427/ze/Modified_HTML-2096577764
Please let us know if you have any other questions.
Regards,
Suriya Balamurugan.
Marked as answer
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
- Marked answer
-
RO Rafael Ortiz
- Jul 27, 2020 04:25 PM UTC
- Jul 29, 2020 09:12 AM UTC