I have wrote a Word document using OpenXML SDK 2.5, this documents give anticipated looks and formatting when I preview it in MS Office.
Now I need to convert this document as HTML document, I came to know about HtmlConverter in OpenXML Powertools, and attempted to use it, Docx to Html conversion using OpenXML power tools failed with NullReferenceException stating Part as null values parameter.
For investigation I've created new Word document (in MS Word) with exact content of my document; This files get converted to Html successfully, So the problem is with the document that I created in C#. I found file size for both varies (Document created from MS Word is heavier, and created with OpenXML SDK seems to be lighter); I've renamed both files as ZIP so as to its check contents, the document.xml markup of both captured below document created with MS office is at Top, and Document markup created with OpenXML SDK is at bottom,
I suspect that the failure of HtmlConverter is due to these markup changes. Is my assumption correct? if so How to add those additional markups in document. here's the code I used to create Word file.
using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(@"D:\15052018.docx", WordprocessingDocumentType.Document))
{
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
Body body = mainPart.Document.AppendChild(new Body());
Paragraph para = body.AppendChild(new Paragraph());
Run run = para.AppendChild(new Run());
RunProperties rpr = new RunProperties(new RunFonts() { Ascii = "Times New Roman" });
run.PrependChild<RunProperties>(rpr);
run.AppendChild(new Text("Welcome"));
wordDocument.Save();
wordDocument.Close();
}
For Html Conversion,
using (WordprocessingDocument doc = WordprocessingDocument.Open(@"D:\15052018.docx", true))
{
HtmlConverterSettings settings = new HtmlConverterSettings() { PageTitle = "My Page Title" };
var html = HtmlConverter.ConvertToHtml(wDoc: doc, htmlConverterSettings: settings);
File.WriteAllText(@"D:\Test1.html", html.ToStringNewLineOnAttributes());
}


