Click or drag to resize

ScreenshotOptions Class

Represents screenshot options: Browser Width and Height, Clip region, PNG or Jpeg, full or partial screenshot.
Inheritance Hierarchy
SystemObject
  SautinSoft.PdfVisionScreenshotOptions

Namespace: SautinSoft.PdfVision
Assembly: SautinSoft.PdfVision (in SautinSoft.PdfVision.dll) Version: 2023.11.2
Syntax
public class ScreenshotOptions

The ScreenshotOptions type exposes the following members.

Constructors
 NameDescription
Public methodCode exampleScreenshotOptions Default constructor for the ScreenshotOptions class.
Top
Properties
 NameDescription
Public propertyBaseUrl 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\").
Public propertyChromiumBaseDirectory 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\.
Public propertyChromiumRevision Gets and sets the Chromium revision. Defaults: Windows - "1115623", Linux - "1115563", MacOs - "1115611".
Public propertyCode exampleClip Specifies clipping region of the page. Default: null.
Public propertyFullPage When true, takes a screenshot of the full scrollable page. Default: true.
Public propertyOmitBackground Hides default white background and allows capturing screenshots with transparency. Default: false.
Public propertyQuality The quality of the image (only for JPEG), between 0-100. Not applicable to PNG images. Default: null.
Public propertyType Specify screenshot type, can be either jpeg or png. Default: Png.
Public propertyCode exampleViewPortOptions Gets or sets browser Width and Height and some other options. Default: 1920x1080.
Top
Methods
 NameDescription
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Top
Example
How to setup ViewPort using C#
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;

            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();
            }
        }
    }
}
How to setup ViewPort using VB.Net
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

            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
See Also