Converts HTML/ASPX file or url to Image file

Namespace:  SautinSoft
Assembly:  SautinSoft.PdfVision (in SautinSoft.PdfVision.dll) Version: 5.1.2.13

Syntax

      
 C#  Visual Basic 
public int ConvertHtmlFileToImageFile(
	string inputHtmlFile,
	string outputImageFile,
	PdfVision..::.eImageFormat imageFormat
)
Public Function ConvertHtmlFileToImageFile ( _
	inputHtmlFile As String, _
	outputImageFile As String, _
	imageFormat As PdfVision..::.eImageFormat _
) As Integer

Parameters

inputHtmlFile
String
Path or url to HTML/ASPX page
outputImageFile
String
Local path to output Image file
imageFormat
PdfVision..::.eImageFormat
Allows to set PdfVision..::.eImageFormat for resulting image

Return Value

0 - converting successfully
1 - can't open input HTML file, check the input path
2 - can't create output file, check the output path
3 - converting failed

Remarks



Examples

CopyHow to convert HTML file to JPEG file in C#
using System;
using System.IO;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
            // Convert HTML to JPEG
            SautinSoft.PdfVision v = new SautinSoft.PdfVision();

            // Set "Edge mode" to support all modern CSS.
            SautinSoft.PdfVision.TrySetBrowserModeEdgeInRegistry();

            v.PageStyle.PageOrientation.Portrait();

            string htmlPath = @"http://nationalzoo.si.edu";
            FileInfo jpegFile = new FileInfo("result.jpg");

            v.ImageStyle.JPEGQuality = 95;
            int ret = v.ConvertHtmlFileToImageFile(htmlPath, jpegFile.FullName, SautinSoft.PdfVision.eImageFormat.Jpeg);

            // 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 produced JPEG in default Viewer.
                System.Diagnostics.Process.Start(jpegFile.FullName);
            }
        }
    }
}
CopyHow to convert HTML file to JPEG file in VB.Net
Imports System.IO

Namespace Sample
    Friend Class Test

        Shared Sub Main(ByVal args() As String)
            ' Convert HTML to JPEG
            Dim v As New SautinSoft.PdfVision()

            ' Set "Edge mode" to support all modern CSS.
            SautinSoft.PdfVision.TrySetBrowserModeEdgeInRegistry()

            v.PageStyle.PageOrientation.Portrait()

            Dim htmlPath As String = "http://nationalzoo.si.edu"
            Dim jpegFile As New FileInfo("result.jpg")

            v.ImageStyle.JPEGQuality = 95
            Dim ret As Integer = v.ConvertHtmlFileToImageFile(htmlPath, jpegFile.FullName, SautinSoft.PdfVision.eImageFormat.Jpeg)

            ' 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 produced JPEG in default Viewer.
                System.Diagnostics.Process.Start(jpegFile.FullName)
            End If
        End Sub
    End Class
End Namespace

See Also