Convert HTML to PNG in C# and VB.Net.
Complete code
using System;
using System.IO;
namespace Sample
{
class Test
{
static void Main(string[] args)
{
// Convert HTML to PNG.
SautinSoft.PdfVision v = new SautinSoft.PdfVision();
// Set "Edge mode" to support all modern CSS.
SautinSoft.PdfVision.TrySetBrowserModeEdgeInRegistry();
string inpFile = @"https://nationalzoo.si.edu";
FileInfo outFile = new FileInfo("Result.png");
int ret = v.ConvertHtmlFileToImageFile(inpFile, outFile.FullName, SautinSoft.PdfVision.eImageFormat.Png);
// 0 - converting successfully
// 1 - can't open input file, check the input path
// 2 - can't create output file, check the output path
// 3 - converting failed
if (ret == 0)
{
// Open the produced PNG image in a default Viewer.
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile.FullName) { UseShellExecute = true });
}
}
}
}
Imports System
Imports System.IO
Namespace Sample
Friend Class Test
Shared Sub Main(ByVal args() As String)
' Convert HTML to PNG.
Dim v As New SautinSoft.PdfVision()
' Set "Edge mode" to support all modern CSS.
SautinSoft.PdfVision.TrySetBrowserModeEdgeInRegistry()
Dim inpFile As String = "https://nationalzoo.si.edu"
Dim outFile As New FileInfo("Result.png")
Dim ret As Integer = v.ConvertHtmlFileToImageFile(inpFile, outFile.FullName, SautinSoft.PdfVision.eImageFormat.Png)
' 0 - converting successfully
' 1 - can't open input file, check the input path
' 2 - can't create output file, check the output path
' 3 - converting failed
If ret = 0 Then
' Open the produced PNG image in a default Viewer.
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile.FullName) With {.UseShellExecute = True})
End If
End Sub
End Class
End Namespace
If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below: