Screenshot |
The ScreenshotOptions type exposes the following members.
Name | Description | |
---|---|---|
ScreenshotOptions | Default constructor for the ScreenshotOptions class. |
Name | Description | |
---|---|---|
BaseUrl | Gets and sets base URL when converting HTML string. All assets such as CSS, JavaScript files and images will be loaded relative to that base URL. Default: null. (For example, "https://example.com", "d:\my webs\"). | |
ChromiumBaseDirectory | Gets and sets a custom directory where will be placed portable Chromium browser. Default value depends of platform (win-x64, win-86, linux-x64 or osx-x64)Current directory\runtimes\win-x64\native\. | |
ChromiumRevision | Gets and sets the Chromium revision. Defaults: Windows - "1115623", Linux - "1115563", MacOs - "1115611". | |
Clip | Specifies clipping region of the page. Default: null. | |
FullPage | When true, takes a screenshot of the full scrollable page. Default: true. | |
OmitBackground | Hides default white background and allows capturing screenshots with transparency. Default: false. | |
Quality | The quality of the image (only for JPEG), between 0-100. Not applicable to PNG images. Default: null. | |
Type | Specify screenshot type, can be either jpeg or png. Default: Png. | |
ViewPortOptions | Gets or sets browser Width and Height and some other options. Default: 1920x1080. |
Name | Description | |
---|---|---|
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) | |
GetHashCode | Serves as the default hash function. (Inherited from Object) | |
GetType | Gets the Type of the current instance. (Inherited from Object) | |
ToString | Returns a string that represents the current object. (Inherited from Object) |
using System; using System.IO; using SautinSoft.PdfVision; namespace Sample { class Program { static void Main(string[] args) { ChangeViewportOptions(); } public static void ChangeViewportOptions() { // This string will contains our input HTML document. string inpHtml = File.ReadAllText(@"..\..\..\example.html"); byte[] imgBytes = null; // Before starting, we recommend to get a free 100-day key: // https://sautinsoft.com/start-for-free/ // Apply the key here: // SautinSoft.PdfVision.SetLicense("..."); PdfVision v = new PdfVision(); ScreenshotOptions options = new ScreenshotOptions() { FullPage = true, // Set 2560 x 1920 ViewPortOptions = new ViewPortOptions() { Width = 2560, Height = 1920 }, Type = ScreenshotType.Png, //Set a custom directory where will be placed portable Chromium browser. //Default value depends of platform (win-x64, win-86, linux-x64 or osx-x64). ChromiumBaseDirectory = Path.GetFullPath(@"..\..\..\..\..\..\Chromium\") }; try { // The whole conversion process will be done completely in memory. imgBytes = v.GetScreenshot(inpHtml, options); // This file is necessary only to show the result. string outFile = new FileInfo("Result.png").FullName; // Save imgBytes to the file and open the result for demonstration purposes. File.WriteAllBytes(outFile, imgBytes); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true }); } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); Console.ReadLine(); } } } }
Imports System Imports System.IO Imports SautinSoft.PdfVision Namespace Sample Friend Class Program Shared Sub Main(ByVal args() As String) ChangeViewportOptions() End Sub Public Shared Sub ChangeViewportOptions() ' This string will contains our input HTML document. Dim inpHtml As String = File.ReadAllText("..\..\..\example.html") Dim imgBytes() As Byte = Nothing ' Before starting, we recommend to get a free 100-day key: ' https://sautinsoft.com/start-for-free/ ' Apply the key here: ' SautinSoft.PdfVision.SetLicense("..."); Dim v As New PdfVision() Dim options As New ScreenshotOptions() With { .FullPage = True, .ViewPortOptions = New ViewPortOptions() With { .Width = 2560, .Height = 1920 }, .Type = ScreenshotType.Png, .ChromiumBaseDirectory = Path.GetFullPath("..\..\..\..\..\..\Chromium\") } Try ' The whole conversion process will be done completely in memory. imgBytes = v.GetScreenshot(inpHtml, options) ' This file is necessary only to show the result. Dim outFile As String = (New FileInfo("Result.png")).FullName ' Save imgBytes to the file and open the result for demonstration purposes. File.WriteAllBytes(outFile, imgBytes) System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True}) Catch ex As Exception Console.WriteLine($"Error: {ex.Message}") Console.ReadLine() End Try End Sub End Class End Namespace