Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Apr 24, 2019 3:29 pm

Hi,

I have an issue when converting word to HTML . I need to apply Encoding UTF8

Currently I have found some alternative for it. Can you please let me know easiest way to do the same.

Document doc = new Document();
doc.LoadFromFile(@"D:\Batch\myDoc.doc");

string htmlstring = string.empty;

using (MemoryStream ms = new MemoryStream())
{
doc.SaveToStream(ms, FileFormat.Html);
htmlstring = System.Text.Encoding.UTF8.GetString(ms.ToArray());

StreamWriter wr = new StreamWriter(@"D:\Batch\myHTMLDoc.htm);
wr.Write(htmlstring );
wr.Close();
}

Jayshree.nandekar
 
Posts: 5
Joined: Wed Apr 24, 2019 3:16 pm

Thu Apr 25, 2019 9:47 am

Hi,

Thank you for your inquiry.
Kindly note that the encoding of HTML directly converted by our Spire.Doc is UTF-8. There is no need to apply the Encoding UTF8 again. Please see the easier way below.
Code: Select all
Document doc = new Document();
doc.LoadFromFile("input.docx");
using (Stream ms = File.Create("WordToHTML.html"))
{
    doc.SaveToStream(ms, FileFormat.Html);
    ms.Flush();
}

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Fri Apr 26, 2019 1:17 pm

Thanks for your Response!

Also I am converting Word doc to PDF. The performance is very low.

for 200 letters it's taking 4min 30seconds.
Below is the code I am using

For each (FileInfo objFile in objFiles)
{
string fileName = Path.GetFileNameWithoutExtension(path + objFile.Name) + ".pdf";
doc.LoadFromFile(path + objFile.Name);
doc.SaveToFile(path + filename , FileFormat.PDF);
}

Jayshree.nandekar
 
Posts: 5
Joined: Wed Apr 24, 2019 3:16 pm

Mon Apr 29, 2019 5:35 am

Hi,

Thank you for your feedback and I am sorry for the late reply as weekend.
Did the 200 letters refer to the 200 Words files? If so, converting one Word to PDF costs 1.35 seconds on your side, I think the speed is reasonable. Which version did you use? I would suggest that you try the latest version (Spire.Doc Pack (hot fix) Version: 7.4.14). Besides, our Spire.Doc provides PS conversion method, which usually has a better performance than the common method you used. You could try it at your end. See sample code below.
Code: Select all
foreach (FileInfo objFile in objFiles)
{
    string fileName = Path.GetFileNameWithoutExtension(path + objFile.Name) + ".pdf";
    doc.LoadFromFile(path + objFile.Name);
    var ps = new ToPdfParameterList
    {
        UsePSCoversion = true
    };       
    doc.SaveToFile(path + filename , ps);
}

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Wed May 01, 2019 9:02 am

Hi,

How is your issue now? Could you please give us some feedback at your convenience? Thanks in advance.

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Return to Spire.Doc