Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created January 18, 2021 21:34
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 aspose-com-gists/88f36d6711b5b9d4dfa67ea1c55af409 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/88f36d6711b5b9d4dfa67ea1c55af409 to your computer and use it in GitHub Desktop.
Convert HTML Webpage to Word File (DOCX/DOC) using C#
// Prepare an HTML code and save it to the file.
var code = @"<span>Hello World!!</span>";
System.IO.File.WriteAllText("document.html", code);
// Initialize an HTML document from the file
using (var document = new HTMLDocument("document.html"))
{
// Initialize DocSaveOptions
var options = new Aspose.Html.Saving.DocSaveOptions();
// Convert HTML webpage to DOCX
Aspose.Html.Converters.Converter.ConvertHTML(document, options, "output.docx");
}
// Prepare an HTML code and save it to the file
var code = @"<span>Hello World!!</span>";
System.IO.File.WriteAllText("document.html", code);
// Set A5 as a page-size
var options = new Aspose.Html.Saving.DocSaveOptions
{
PageSetup =
{
AnyPage = new Aspose.Html.Drawing.Page()
{
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromInches(8.3f), Aspose.Html.Drawing.Length.FromInches(5.8f))
}
}
};
// Convert HTML document to DOCX
Aspose.Html.Converters.Converter.ConvertHTML("document.html", options, "output.docx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment