Learn how to convert HTML to JPG in C# : https://blog.aspose.com/html/convert-html-to-jpg-in-csharp/
The following topics are covered in this article:
Learn how to convert HTML to JPG in C# : https://blog.aspose.com/html/convert-html-to-jpg-in-csharp/
The following topics are covered in this article:
// This code example demonstrates how to convert an HTML file to a JPG image. | |
// Load input HTML file | |
var document = new HTMLDocument(@"C:\Files\sample.html"); | |
// Initialize ImageSaveOptions | |
var options = new ImageSaveOptions(); | |
// Specify image format as Jpeg | |
options.Format = ImageFormat.Jpeg; | |
// Convert HTML to JPG | |
Converter.ConvertHTML(document, options, @"C:\Files\output.jpg"); |
// This code example demonstrates how to generate HTML string output in a JPG image. | |
string htmlString = @"<style> | |
.st | |
{ | |
color: green; | |
} | |
</style> | |
<div id=id1>Aspose.Html rendering Text in Black Color</div> | |
<div id=id2 class=''st''>Aspose.Html rendering Text in Green Color</div><div id=id3 class=''st'' style='color: blue;'>Aspose.Html rendering Text in Blue Color</div> | |
<div id=id3 class=''st'' style='color: red;'><font face='Arial'>Aspose.Html rendering Text in Red Color</font></div>"; | |
// Initialize ImageSaveOptions | |
var options = new ImageSaveOptions(ImageFormat.Jpeg); | |
// Invoke the ConvertHTML method to convert the HTML code to PDF | |
Converter.ConvertHTML(htmlString, ".", options, @"C:\Files\HtmlStringToJpg.jpg"); |
// This code example demonstrates how to convert an HTML file to JPG images with image save options. | |
// Load input HTML file | |
var document = new HTMLDocument(@"C:\Files\sample.html"); | |
// Initialize ImageSaveOptions | |
var options = new ImageSaveOptions(ImageFormat.Jpeg); | |
options.SmoothingMode = SmoothingMode.HighQuality; | |
options.HorizontalResolution = 200; | |
options.VerticalResolution = 200; | |
options.BackgroundColor = Color.AliceBlue; | |
// Set page size and margings | |
options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(600, 800), new Margin(10, 10, 10, 10)); | |
// Convert HTML to JPG | |
Converter.ConvertHTML(document, options, @"C:\Files\output_saveOptions.jpg"); |
// This code example demonstrates how to convert a live webpage to a JPG image. | |
// URL | |
Url url = new Url("https://docs.aspose.com/html/net/"); | |
// Initialize ImageSaveOptions | |
var options = new ImageSaveOptions(ImageFormat.Jpeg); | |
// Convert the HTML to JPG | |
Converter.ConvertHTML(url, options, @"C:\Files\outputFromURL.jpg"); |