Convert HTML to JPEG на C# и .NET


Полный код

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();

            string inpFile = @"https://nationalzoo.si.edu";
            FileInfo outFile = new FileInfo("Result.jpg");

            v.ImageStyle.JPEGQuality = 95;
            int ret = v.ConvertHtmlFileToImageFile(inpFile, outFile.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 the produced JPEG 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 JPEG
            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.jpg")

            v.ImageStyle.JPEGQuality = 95
            Dim ret As Integer = v.ConvertHtmlFileToImageFile(inpFile, outFile.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 the produced JPEG 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

Скачать


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу [email protected] или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.