Skip to content

Instantly share code, notes, and snippets.

@farhan-raza
Created October 2, 2020 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farhan-raza/237a7d38b3b2d61b7bf4952c33e7165b to your computer and use it in GitHub Desktop.
Save farhan-raza/237a7d38b3b2d61b7bf4952c33e7165b to your computer and use it in GitHub Desktop.
Convert Word DOC or DOCX to HTML, MHTML in C# VB.NET
// Load the document from disk.
Document doc = new Document(dataDir + "Test File.docx");
// Set HtmlSaveOptions
HtmlSaveOptions options = new HtmlSaveOptions();
options.SaveFormat = SaveFormat.Html;
// Save the document into HTML
doc.Save(dataDir + "Document.html", options);
// Load the document from disk.
Document doc = new Document(dataDir + "Test File (doc).docx");
HtmlSaveOptions options = new HtmlSaveOptions();
// HtmlSaveOptions.ExportRoundtripInformation property specifies
// Whether to write the roundtrip information when saving to HTML, MHTML or EPUB.
// Default value is true for HTML and false for MHTML and EPUB.
options.ExportRoundtripInformation = true;
doc.Save(dataDir + "ExportRoundtripInformation_out.html", options);
// Load the document from disk.
Document doc = new Document(dataDir + "Test File.docx");
// Set HtmlSaveOptions
HtmlSaveOptions options = new HtmlSaveOptions();
options.SaveFormat = SaveFormat.Mhtml;
// Save the document into MHTML
doc.Save(dataDir + "Document.mhtml", options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment