Created
April 22, 2022 09:11
-
-
Save aspose-com-gists/1f36aa85dca7fa2c31ea770ac0afbdda to your computer and use it in GitHub Desktop.
Convert HTML to MHT or MHTML File Programmatically in C# .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prepare HTML code with a link to another file and save it to the file as 'document.html' | |
string code = "<span>Hello, World!!</span> " + | |
"<a href='document2.html'>click</a>"; | |
File.WriteAllText("document.html", code); | |
// Prepare HTML code and save it to the file as 'document2.html' | |
code = @"<span>Hello, World!!</span>"; | |
File.WriteAllText("document2.html", code); | |
// Change the value of the resource linking depth to 1 in order to convert document with directly linked resources | |
MHTMLSaveOptions options = new MHTMLSaveOptions() | |
{ | |
ResourceHandlingOptions = | |
{ | |
MaxHandlingDepth = 1 | |
} | |
}; | |
// Convert HTML to MHTML | |
Converter.ConvertHTML("document.html", options, "output.mht"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize an HTML document from the file | |
HTMLDocument document = new HTMLDocument("input.html"); | |
// Initialize MHTMLSaveOptions object | |
MHTMLSaveOptions options = new MHTMLSaveOptions(); | |
// Convert HTML to MHTML | |
Converter.ConvertHTML(document, options, "output.mht"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment