0

I am converting a single HTML page to Doc using spire doc. I need to convert multiple html pages from single folder to single Doc. How this can be done. Can anyone give some idea or any library available to achieve this?

Please find my code to convert single HTML to Doc.

 Spire.Doc.Document document = new Spire.Doc.Document();
 document.LoadFromFile(@"D:\DocFilesConvert\htmlfile.html", Spire.Doc.FileFormat.Html, XHTMLValidationType.None);
 document.SaveToFile(@"D:\DocFilesConvert\docfiless.docx", Spire.Doc.FileFormat.Docx);
Shubashree Ravi
  • 261
  • 1
  • 16

1 Answers1

0

There seems no direct way to achieve this. One workaround I find is to convert each HTML document to a single Word file, and then merge these Word files in one file.

//get HTML file paths
string[] htmlfilePaths = new string[]{

    @"F:\Documents\Html\1.html",
    @"F:\Documents\Html\2.html",
    @"F:\Documents\Html\3.html"
};

//create Document array
Document[] docs = new Document[htmlfilePaths.Length];

for (int i = 0; i < htmlfilePaths.Length; i++)
{
    //load each HTML to a sperate Word file
    docs[i] = new Document(htmlfilePaths[i], FileFormat.Html);

    //combine these Word files in one file
    if (i>=1)
    {
        foreach (Section sec in docs[i].Sections)
        {
            docs[0].Sections.Add(sec.Clone());
        }                 
    }
}

//save to a Word document
docs[0].SaveToFile("output.docx", FileFormat.Docx2013);
vaalex
  • 109
  • 3