Click or drag to resize
Pdf Library for .NET

HtmlToImage Class

Converts HTML documents and web pages to raster images.
Inheritance Hierarchy
SystemObject
  SelectPdf.UniversalHtmlToImage

Namespace: SelectPdf.Universal
Assembly: SelectPdf.Universal (in SelectPdf.Universal.dll) Version: 26.4
Syntax
public class HtmlToImage

The HtmlToImage type exposes the following members.

Constructors
 NameDescription
Public methodHtmlToImageInitializes a new converter with the default virtual browser width (1024px).
Public methodHtmlToImage(Int32)Initializes a new converter with the specified virtual browser width.
Public methodHtmlToImage(Int32, Int32)Initializes a new converter with the specified virtual browser width and height.
Top
Properties
 NameDescription
Public propertyAuthenticationPasswordThe password for HTTP basic authentication.
Public propertyAuthenticationUsernameThe user name for HTTP basic authentication.
Public propertyChromiumEnginePathThe path to the conversion engine folder. Empty resolves it next to the assembly.
Public propertyChromiumEngineTemporaryFilesPathThe path used by the conversion engine for temporary files.
Public propertyClickElementsDelayAfterDelay (ms) after clicking the elements in ClickElementsSelectors.
Public propertyClickElementsDelayBeforeDelay (ms) before clicking the elements in ClickElementsSelectors.
Public propertyClickElementsSelectorsCSS selectors of elements to click before capturing.
Public propertyConversionDelay Additional time in seconds the converter waits after the web page has loaded, before it is rendered.
Public propertyCustomCSSExtra CSS injected into the page before capture.
Public propertyDenyLocalFileAccessWhen true, local file access is denied during the conversion.
Public propertyDrawBackgroundWhether the page background is drawn into the image. Default true.
Public propertyEnableOfflineModeWhether the browser runs in offline mode. Default false.
Public propertyForceOutOfProcess Runs this conversion in a separate engine process, whatever ChromiumEngineHostMode says.
Public propertyHttpCache Selects what the engine's HTTP cache keeps from this conversion for the next one.
Public propertyHttpCookiesHTTP cookies sent with the request.
Public propertyHttpHeadersAdditional HTTP request headers.
Public propertyHttpPostParametersHTTP POST parameters (turns the request into a POST).
Public propertyImageFormat The format of the image returned by ConvertUrl(String) / ConvertHtmlString(String). Default Png (the engine's native output). Set to Jpeg, Bmp, or Tiff to receive the bytes already encoded in that format.
Public propertyJavaScriptEnabledWhether JavaScript is enabled during rendering. Default true.
Public propertyLazyImagesLoadingDelayDelay (ms) used while triggering lazy image loading. Default 40.
Public propertyLazyImagesLoadingEnabledWhether lazy-loaded images are forced to load before capture. Default true.
Public propertyLFNThe path of the diagnostic log file written during conversion. Empty disables logging.
Public propertyLoginOptionsForm-login options performed before navigating to the target page.
Public propertyMaxConversionTimeMaximum time (seconds) for the whole conversion. Default 60.
Public propertyMaxPageLoadTime The time in seconds to wait for the web page to load. Obsolete: use NavigationTimeout.
Obsolete
Public propertyMinPageLoadTime Additional time in seconds to wait before the web page is rendered. Obsolete: use ConversionDelay.
Obsolete
Public propertyNavigationTimeout The time in seconds the converter waits for the web page to load.
Public propertyPostLoadingScriptJavaScript run after the page loads, before capture.
Public propertyPostLoadingScriptDelayAfterDelay (ms) after running PostLoadingScript.
Public propertyProxyOptionsProxy settings for the conversion.
Public propertyRenderingEngine Gets or sets the rendering engine used to load and render the html. Chromium is the only engine and the default.
Public propertyStartupModeThe startup mode of the conversion (Automatic or Manual).
Public propertyStartupScriptJavaScript run at startup (before the page loads) in Manual startup mode.
Public propertyVisibleWebElementId Convert only the html element with the specified id.
Obsolete
Public propertyVisibleWebElementSelector Convert only the part of the page matched by this CSS selector; the rest is ignored.
Public propertyWebGlEnabled Controls WebGL support in the rendering engine.
Public propertyWebPageFixedSizeWhen true, the virtual browser uses the exact WebPageWidth / WebPageHeight without auto-sizing.
Public propertyWebPageHeightThe virtual browser height, in pixels. Default 0 (auto — the full content height).
Public propertyWebPageWidthThe virtual browser width, in pixels. Default 1024.
Public propertyWindowStatusWhen set, the engine waits until window.status equals this value before capturing.
Top
Methods
 NameDescription
Public methodCode exampleConvertHtmlString(String)Converts the specified HTML string to an image in ImageFormat (PNG by default).
Public methodConvertHtmlString(String, String)Converts the specified HTML string to an image in ImageFormat (PNG by default), resolving relative urls against the base url.
Public methodCode exampleConvertHtmlStringAsync(String)Asynchronously converts the specified HTML string to an image in ImageFormat (PNG by default).
Public methodConvertHtmlStringAsync(String, String)Asynchronously converts the specified HTML string to an image in ImageFormat (PNG by default), resolving relative urls against the base url.
Public methodConvertHtmlStringAsync(String, CancellationToken)Asynchronously converts the specified HTML string to an image in ImageFormat (PNG by default), stopping when the specified token is cancelled.
Public methodConvertHtmlStringAsync(String, String, CancellationToken)Asynchronously converts the specified HTML string to an image in ImageFormat (PNG by default), resolving relative urls against the base url and stopping when the specified token is cancelled.
Public methodCode exampleConvertUrlConverts the web page at the specified url to an image in ImageFormat (PNG by default).
Public methodCode exampleConvertUrlAsync(String)Asynchronously converts the web page at the specified url to an image in ImageFormat (PNG by default).
Public methodConvertUrlAsync(String, CancellationToken)Asynchronously converts the web page at the specified url to an image in ImageFormat (PNG by default), stopping when the specified token is cancelled.
Top
Remarks
The conversion produces a full-page PNG screenshot, returned as a byte[]. Rendering runs on the same out-of-process conversion engine used by HtmlToPdf.
Example
SelectPdf.Universal.HtmlToImage converter =
    new SelectPdf.Universal.HtmlToImage(1024);
byte[] png = converter.ConvertUrl("https://www.google.com");
System.IO.File.WriteAllBytes("page.png", png);
See Also