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
Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу support@sautinsoft.ru или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже: