- Home
- Forum
- ASP.NET Web Forms
- Convert Html String to word document
Convert Html String to word document
I have tried converting HTML string to word document. But am getting error "docio support only well formatted xhtml". Here is my code sample
string htmlText = htmlContent;
WordDocument wordDocument = new WordDocument();
IWSection section = wordDocument.AddSection();
section.Body.IsValidXHTML(new XhtmlString(htmlText), wordDocument.XHTMLValidateOption);
section.Body.InsertXHTML(htmlContent);
wordDocument.Save("Sample.doc", FormatType.Html, Response, HttpContentDisposition.InBrowser);
Above is my code, can you help me in this.Thanks.,
SIGN IN To post a reply.
10 Replies
MJ
Mohanaselvam Jothi
Syncfusion Team
July 8, 2019 07:02 AM UTC
Hi Sarvana,
Thank you for contacting Syncfusion support.
Essential DocIO supports converting the HTML file into Word document and vice versa. It supports HTML with XHTML 1.0 compliant for HTML conversion. We suspect that the input HTML doesn’t meet XHTML 1.0 compliant, so the reported problem occurs at your end.
Please refer the below UG documentation link to know more about converting the HTML file into Word document using DocIO:
https://help.syncfusion.com/file-formats/docio/conversion#html-conversion
Please let us know if you have any other questions.
Regards,
Mohanaselvam J
Thank you for contacting Syncfusion support.
Essential DocIO supports converting the HTML file into Word document and vice versa. It supports HTML with XHTML 1.0 compliant for HTML conversion. We suspect that the input HTML doesn’t meet XHTML 1.0 compliant, so the reported problem occurs at your end.
Please refer the below UG documentation link to know more about converting the HTML file into Word document using DocIO:
https://help.syncfusion.com/file-formats/docio/conversion#html-conversion
Please let us know if you have any other questions.
Regards,
Mohanaselvam J
SA
Sarvana
July 8, 2019 12:10 PM UTC
Hey Mohan,
can you provide some samples.
PR
Poorani Rajendran
Syncfusion Team
July 9, 2019 09:32 AM UTC
Hi Saravana,
Thank you for your update.
We have prepared sample for converting HTML file into Word document and it can be downloaded from the below link:
https://www.syncfusion.com/downloads/support/forum/145749/ze/CreateWordFile1693168057_21530295238
Please let us know if you have any other questions.
Regards,
Poorani Rajendran
Thank you for your update.
We have prepared sample for converting HTML file into Word document and it can be downloaded from the below link:
https://www.syncfusion.com/downloads/support/forum/145749/ze/CreateWordFile1693168057_21530295238
Please let us know if you have any other questions.
Regards,
Poorani Rajendran
SA
Sarvana
July 18, 2019 07:33 AM UTC
Hi,
Am able to convert the Html string to PDF file, but the same Html string is using for converting word, it's giving the error, am not able to convert, I have tried using your samples, from there also I facing the problems. Herewith I have attached the my Html string in the notepad format and pdf in Image format.
PR
Poorani Rajendran
Syncfusion Team
July 18, 2019 02:11 PM UTC
Hi Saravana,
Thank you for your update.
We have tried to reproduce the reported problem while converting HTML string into Word document, but it works properly at our end. For your reference, we have attached the sample application which we tried at our end and it can be downloaded from the below link:
https://www.syncfusion.com/downloads/support/forum/145749/ze/CreateWordFile1693168057_21530295238
We suspect that the problem might be due to the code snippet and HTML input string used at your end. So, could you please share us the input HTML string and modified sample of above application to reproduce the issue. Based on the details, we will check on your problem and will share you the solution at the earliest.
Please let us know if you have any other questions.
Regards,
Poorani Rajendran
Thank you for your update.
We have tried to reproduce the reported problem while converting HTML string into Word document, but it works properly at our end. For your reference, we have attached the sample application which we tried at our end and it can be downloaded from the below link:
https://www.syncfusion.com/downloads/support/forum/145749/ze/CreateWordFile1693168057_21530295238
We suspect that the problem might be due to the code snippet and HTML input string used at your end. So, could you please share us the input HTML string and modified sample of above application to reproduce the issue. Based on the details, we will check on your problem and will share you the solution at the earliest.
Please let us know if you have any other questions.
Regards,
Poorani Rajendran
PR
Poorani Rajendran
Syncfusion Team
July 19, 2019 02:03 PM UTC
Hi Saravana,
Thank you for your update.
We have tried in the sample application as provided in our previous update (Updated on 7/18/2019) using your input file which is mailed through our Syncfusion support(HtmlFile), it throws not well formatted exception. On further analyzed your given input text file, we have found that it is not in the standard format of XHTML 1.0 compliant. Essential DocIO supports HTML with XHTML 1.0 compliant for converting HTML file to Word document and vice versa.
We suspect that the code snippet or HTML string used at your end is differed from the file you sent. So please share us the proper input text file and modified code snippet in sample application which is updated (Updated on 7/18/2019).
Based on the above details, we will analyze further on the reported problem and will provide you the appropriate solution at the earliest.
Please let me know if you have any other questions.
Regards,
Poorani Rajendran
Thank you for your update.
We have tried in the sample application as provided in our previous update (Updated on 7/18/2019) using your input file which is mailed through our Syncfusion support(HtmlFile), it throws not well formatted exception. On further analyzed your given input text file, we have found that it is not in the standard format of XHTML 1.0 compliant. Essential DocIO supports HTML with XHTML 1.0 compliant for converting HTML file to Word document and vice versa.
We suspect that the code snippet or HTML string used at your end is differed from the file you sent. So please share us the proper input text file and modified code snippet in sample application which is updated (Updated on 7/18/2019).
Based on the above details, we will analyze further on the reported problem and will provide you the appropriate solution at the earliest.
Please let me know if you have any other questions.
Regards,
Poorani Rajendran
PG
Pon Geetha A J
Syncfusion Team
July 24, 2019 10:07 AM UTC
Hello,
The same Html is used for converting Html to Pdf using Syncfusion. It's converting fine. But we are facing the issue while converting to Word format.
P.Sarvan MCA.,
The same Html is used for converting Html to Pdf using Syncfusion. It's converting fine. But we are facing the issue while converting to Word format.
P.Sarvan MCA.,
PR
Poorani Rajendran
Syncfusion Team
July 24, 2019 12:16 PM UTC
Hi Saravana,
Thank you for your update.
From the given details, we suspect that you are using Essential PDF library to convert HTML into PDF directly (without any intermediate conversion) so, the reported problem doesn’t occurred at your end.
Essential DocIO is a Word library which supports HTML with XHTML 1.0 compliant for HTML conversions. As mentioned in our previous update, we have found that the input HTML content doesn’t meet the standard format of XHTML 1.0 compliant. So, it throws error while converting given HTML to Word document using Essential DocIO.Thank you for your update.
From the given details, we suspect that you are using Essential PDF library to convert HTML into PDF directly (without any intermediate conversion) so, the reported problem doesn’t occurred at your end.
To resolve this problem at your end, we suggest you modify the input HTML string into well formatted HTML string with XHTML 1.0 compliant and then convert into Word document using DocIO.
Please let us know if you have any other questions.
Regards,
Poorani Rajendran
PG
Pon Geetha A J
Syncfusion Team
August 2, 2019 04:13 AM UTC
Hello,
I have used the same code which you sent previously. I just added the table in the code, but still, am not able to convert the word document. herewith am sending you code samples.
string htmlText = @"<html><head><title> XHTML to Doc </title></head>
<body><p><b>XHTML to Doc - Strict XHTML example</b></p><p></p>
<table>
< tr >
< th > Firstname </ th >
< th > Lastname </ th >
< th > Age </ th >
</ tr >
< tr >
< td > Jill </ td >
< td > Smith </ td >
< td > 50 </ td >
</ tr >
< tr >
< td > Eve </ td >
< td > Jackson </ td >
< td > 94 </ td >
</ tr >
</ table >
< p><b>Essential DocIO</b> now supports converting valid XHTML content to Doc content. The passed in content should be either XHTML 1.0 or 1.1 compliant.</p><p></p>
<p><b>XHTML 1.0 Strict</b></p>
<p>It is the same as HTML 4.01 Strict, but it follows XML syntax rules.</p>
</body></html>";
WordDocument wordDocument = new WordDocument();
IWSection section = wordDocument.AddSection();
section.Body.IsValidXHTML(htmlText, wordDocument.XHTMLValidateOption);
section.Body.InsertXHTML(htmlText);
wordDocument.Save("ResultThree.doc", FormatType.Doc, Response, HttpContentDisposition.InBrowser);
wordDocument.Close();
The above image is the error am getting while running the applicat
P.Sarvan MCA.,
I have used the same code which you sent previously. I just added the table in the code, but still, am not able to convert the word document. herewith am sending you code samples.
string htmlText = @"<html><head><title> XHTML to Doc </title></head>
<body><p><b>XHTML to Doc - Strict XHTML example</b></p><p></p>
<table>
< tr >
< th > Firstname </ th >
< th > Lastname </ th >
< th > Age </ th >
</ tr >
< tr >
< td > Jill </ td >
< td > Smith </ td >
< td > 50 </ td >
</ tr >
< tr >
< td > Eve </ td >
< td > Jackson </ td >
< td > 94 </ td >
</ tr >
</ table >
< p><b>Essential DocIO</b> now supports converting valid XHTML content to Doc content. The passed in content should be either XHTML 1.0 or 1.1 compliant.</p><p></p>
<p><b>XHTML 1.0 Strict</b></p>
<p>It is the same as HTML 4.01 Strict, but it follows XML syntax rules.</p>
</body></html>";
WordDocument wordDocument = new WordDocument();
IWSection section = wordDocument.AddSection();
section.Body.IsValidXHTML(htmlText, wordDocument.XHTMLValidateOption);
section.Body.InsertXHTML(htmlText);
wordDocument.Save("ResultThree.doc", FormatType.Doc, Response, HttpContentDisposition.InBrowser);
wordDocument.Close();
The above image is the error am getting while running the applicat
P.Sarvan MCA.,
PR
Poorani Rajendran
Syncfusion Team
August 2, 2019 06:44 AM UTC
Hi Sarvan,
Thank you for your update.
On analyzing with your input HTML string, we have found that the given input HTML content doesn’t meet the standard format of XHTML 1.0 compliant. As mentioned on our earlier update (Updated on 7/24/2019), Essential DocIO is a Word library which supports HTML with XHTML 1.0 compliant for HTML conversions. So, it throws error while converting given HTML to Word document using Essential DocIO.
To meet your requirement, we have modified the input HTML string to standard format of XHTML 1.0 compliant. We have prepared a sample application along with modified input HTML string and it can be downloaded from the below link :
https://www.syncfusion.com/downloads/support/forum/145749/ze/ModifiedHTMLString1681353906
Please refer the below UG documentation link to know more about working with HTML document using DocIO:
https://help.syncfusion.com/file-formats/docio/html
Please let us know if you have any other questions.
Regards,
Poorani Rajendran
Thank you for your update.
On analyzing with your input HTML string, we have found that the given input HTML content doesn’t meet the standard format of XHTML 1.0 compliant. As mentioned on our earlier update (Updated on 7/24/2019), Essential DocIO is a Word library which supports HTML with XHTML 1.0 compliant for HTML conversions. So, it throws error while converting given HTML to Word document using Essential DocIO.
To meet your requirement, we have modified the input HTML string to standard format of XHTML 1.0 compliant. We have prepared a sample application along with modified input HTML string and it can be downloaded from the below link :
https://www.syncfusion.com/downloads/support/forum/145749/ze/ModifiedHTMLString1681353906
Please refer the below UG documentation link to know more about working with HTML document using DocIO:
https://help.syncfusion.com/file-formats/docio/html
Please let us know if you have any other questions.
Regards,
Poorani Rajendran
SIGN IN To post a reply.
- 10 Replies
- 4 Participants
-
SA Sarvana
- Jul 6, 2019 07:45 AM UTC
- Aug 2, 2019 06:44 AM UTC