public void HTMLtoMHTMLWithMHTMLSaveOptionsTest() { // Prepare HTML code with a link to another file and save it to the file as 'document.html' var 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); string savePath = Path.Combine(OutputDir, "output-options.mht"); // Change the value of the resource linking depth to 1 in order to convert document with directly linked resources var options = new MHTMLSaveOptions() { ResourceHandlingOptions = { MaxHandlingDepth = 1 } }; // Convert HTML to MHTML Converter.ConvertHTML("document.html", options, savePath); Assert.True(File.Exists(savePath)); }
private void SaveDocument(string name, String htmlPath, int handlingDepth) { var outPath = Path.Combine(_htmlOutputPath, name); Console.WriteLine(Path.GetFullPath(outPath)); MHTMLSaveOptions mhtmlSaveOptions = new MHTMLSaveOptions(); mhtmlSaveOptions.ResourceHandlingOptions.UrlRestriction = UrlRestriction.SameHost; mhtmlSaveOptions.ResourceHandlingOptions.MaxHandlingDepth = handlingDepth; using (var htmlContainer = new HTMLDocument(htmlPath)) { htmlContainer.Save(outPath, mhtmlSaveOptions); } }
public static void Run() { // ExStart:1 // The path to the documents directory string dataDir = RunExamples.GetDataDir_Data(); // Source HTML Document HTMLDocument htmlDocument = new HTMLDocument(dataDir + "input.html"); // Initialize MHTMLSaveOptions MHTMLSaveOptions options = new MHTMLSaveOptions(); // Set the resource handling rules options.ResourceHandlingOptions.MaxHandlingDepth = 1; // Output file path string outputPDF = dataDir + "HTMLtoMHTML_Output.mht"; // Convert HTML to MHTML Converter.ConvertHTML(htmlDocument, options, outputPDF); // ExEnd:1 }
public void ConvertHTMLtoMHTMLTest() { // Prepare a path to a source HTML file string documentPath = Path.Combine(DataDir, "drawing.html"); // Prepare a path for converted file saving string savePath = Path.Combine(OutputDir, "drawing-output.mht"); // Initialize an HTML document from the file using var document = new HTMLDocument(documentPath); // Initialize MHTMLSaveOptions var options = new MHTMLSaveOptions(); // Convert HTML to MHTML Converter.ConvertHTML(document, options, savePath); Assert.True(File.Exists(savePath)); }