Class HtmlToImageConverter
- Namespace
- EvoPdf
- Assembly
- evohtmltopdf.dll
This class offers the necessary methods to create a raster image from a web page at given URL or from a HTML string. The generated image can be saved into a memory buffer or into a file
[ClassInterface(ClassInterfaceType.AutoDual)]
public class HtmlToImageConverter
- Inheritance
-
HtmlToImageConverter
- Derived
- Inherited Members
Constructors
HtmlToImageConverter()
Creates a HTML to Image converter using the default width and height for the HTML viewer. The default HTML viewer width is 1024 pixels and the default HTML viewer height is 0 which means the HTML viewer height will be automatically determined based on the HTML content and the HTML viewer width in order to make visible the whole HTML content. If the HTML content is not entirely visible in the HTML viewer at the default width of 1024 pixels, the ClipHtmlView property will control whether the HTML content is clipped or the HTML viewer width is automatically extended to make visible the whole HTML content. By default the ClipHtmlView property is false and the HTML viewer is automatically extended in width to make visible the whole HTML content. The width and height of the HTML viewer can also be controlled by the HtmlViewerWidth and HtmlViewerHeight properties of the HtmlToImageConverter class.
public HtmlToImageConverter()
HtmlToImageConverter(int)
Creates a HTML to Image converter using the specified width in pixels and the default height for the HTML viewer. The default HTML viewer height is 0 which means the HTML viewer height will be automatically determined based on the HTML content and the HTML viewer width in order to make visible the whole HTML content. If the content is not entirely visible in the HTML viewer at the specified width, the ClipHtmlView property will control whether the HTML content is clipped or the HTML viewer width is automatically extended to make visible the whole HTML content. By default the ClipHtmlView property is false and the HTML viewer is automatically extended in width to make visible the whole HTML content. The width and height of the HTML viewer can also be controlled by the HtmlViewerWidth and HtmlViewerHeight properties of the HtmlToImageConverter class.
public HtmlToImageConverter(int htmlViewerWidth)
Parameters
htmlViewerWidth
intThe preferred HTML viewer width in pixels.
HtmlToImageConverter(int, int)
Creates a HTML to Image converter using the specified width and height in pixels for the HTML viewer. If the specified HTML viewer height is 0 the HTML viewer height will be automatically determined based on the HTML content and the HTML viewer width in order to make visible the whole HTML content. If the content is not entirely visible in the HTML viewer at the specified width, the ClipHtmlView property will control whether the HTML content is clipped or the HTML viewer width is automatically extended to make visible the whole HTML content. By default the ClipHtmlView property is false and the HTML viewer is automatically extended in width to make visible the whole HTML content. The width and height of the HTML viewer can also be controlled by the HtmlViewerWidth and HtmlViewerHeight properties of the HtmlToImageConverter class.
public HtmlToImageConverter(int htmlViewerWidth, int htmlViewerHeight)
Parameters
htmlViewerWidth
intThe preferred HTML viewer width in pixels.
htmlViewerHeight
intThe preferred HTML viewer height in pixels.
Properties
AuthenticationOptions
This property can be set with an username and a password in order to authenticate to the web server before accessing the URL to be converted in HTML to Image converter. They can be used for example to resolve the IIS Integrated Windows Authentication or other types of IIS authentication.
public AuthenticationOptions AuthenticationOptions { get; }
Property Value
ClipHtmlView
If the HTML content is not entirely visible in the HTML viewer of the HTML to Image converter at the specified width, the ClipHtmlView property will control whether the HTML content is clipped or the HTML viewer width is automatically extended to make visible the whole HTML content. The HTML viewer width is given by the HtmlViewerWidth property. The default value of this property is false.
public bool ClipHtmlView { get; set; }
Property Value
ConversionDelay
An additional time in seconds to wait for asynchronous items to be completely loaded or for a web page redirect to finish before starting the rendering in HTML to Image converter. Default value is 2.
public int ConversionDelay { get; set; }
Property Value
DefaultHtmlEncoding
The default HTML document text encoding to be used if there is no charset meta tag defined in the HTML document. By default this property is not set and an auto determined text encoding will be used by converter
public string DefaultHtmlEncoding { get; set; }
Property Value
DownloadAllResources
Gets or sets a flag indicating if the HTML to Image converter should try to download all the resources even if this could cause a slower conversion. The default value is false.
public bool DownloadAllResources { get; set; }
Property Value
Enable3DTransformations
Gets or sets a flag indicating if the accelerated CSS 3D transformations are enabled in the HTML to Image converter. The default value is false
public bool Enable3DTransformations { get; set; }
Property Value
EnableAccelerated2DCanvas
Gets or sets a flag indicating if the accelerated 2D canvas is enabled in the HTML to Image converter. The default value is false
public bool EnableAccelerated2DCanvas { get; set; }
Property Value
EnableHttp2
Gets or sets a flag indicating if the HTTP2 protocol is enabled in HTML to Image converter. The property has effect only in NE version of the library. The default value is false
public bool EnableHttp2 { get; set; }
Property Value
EnablePersistentStorage
Gets or sets a flag indicating if the persistent local storage is enabled in the HTML to Image converter. The default value is false
public bool EnablePersistentStorage { get; set; }
Property Value
EnableWebGL
Gets or sets a flag indicating if the WebGL is enabled in the HTML to Image converter. The default value is false
public bool EnableWebGL { get; set; }
Property Value
EvoInternalFileName
Sets the full path of evointernal.dat helper file of the HTML to Image converter. By default this file is expected to be found in the same folder with evohtmltopdf.dll assembly.
public string EvoInternalFileName { set; }
Property Value
ExtensionsEnabled
Gets or sets a flag indicating if the HTML viewer extensions are executed during the HTML to Image conversion. The default value is false and no extension is executed. The Flash player for Mozilla Firefox must be installed in order to execute the flash content from HTML
public bool ExtensionsEnabled { get; set; }
Property Value
HtmlViewerHeight
Gets or sets the HTML viewer height in pixels in the HTML to Image converter. If the specified HTML viewer height is 0 the HTML viewer height will be automatically determined based on the HTML content and the HTML viewer width in order to make visible the whole HTML content. The HTML viewer width is given by the HtmlViewerWidth property. If the HTML content is not entirely visible in the HTML viewer at the specified width, the ClipHtmlView property will control whether the HTML content is clipped or the HTML viewer width is automatically extended to make visible the whole HTML content. The HTML viewer height can also be specified in the HtmlToImageConverter class contructor. The default value is 0 to automatically determine the HTML viewer height based on the HTML content and the HTML viewer width.
public int HtmlViewerHeight { get; set; }
Property Value
HtmlViewerWidth
Gets or sets the preferred HTML viewer width in pixels in the HTML to Image converter. If the HTML content is not entirely visible in the HTML viewer at the specified width, the ClipHtmlView property will control whether the HTML content is clipped or the HTML viewer width is automatically extended to make visible the whole HTML content. By default the ClipHtmlView property is false and the HTML viewer is automatically extended in width to make visible the whole HTML content. The HTML viewer width can also be specified in the HtmlToImageConverter class constructor. The default value is 1024 pixels.
public int HtmlViewerWidth { get; set; }
Property Value
HtmlViewerZoom
Gets or sets the HTML viewer zoom percentage in HTML to Image Converter similar to zoom level in a browser. The default value of this property is 100
public int HtmlViewerZoom { get; set; }
Property Value
HttpPostFields
Returns the collection of HTTP POST fields to be used when accessing a web page in the HTML to Image converter. If there are elements in collection then the converter will make a POST request to the web page URL with the fields from this collection, otherwise it will make a GET request
public NameValueCollection HttpPostFields { get; }
Property Value
HttpRequestCookies
Gets a collection of custom HTTP cookies to be sent by the HTML to Image converter to the web server when the web page to convert and the resources (image, css, etc) referenced by the web page are requested. A cookie is defined by a name and a value pair that can be added to the collection using the Add(string, string) method of the HttpRequestCookies property.
public NameValueCollection HttpRequestCookies { get; }
Property Value
HttpRequestHeaders
Gets a collection of custom HTTP headers to be sent by the HTML to Image converter to the web server when the web page is requested from a URL. A custom HTTP header is defined by a name and a value pair that can be added to the collection using the Add(string, string) method of the HttpRequestHeaders property. The PersistentHttpRequestHeaders property can be set on true to instruct the converter to send the custom headers each time an external resource (image, css, etc) referenced by the web page is requested. By default the PersistentHttpRequestHeaders property is false and the custom headers are not automatically sent to the web server when the web page resources are requested. The custom HTTP headers can be used to define cookies, authentication options, URL referrer or any other HTTP header to be sent to the web browser. The preferred method to send cookies is to use the HttpRequestCookies property.
public NameValueCollection HttpRequestHeaders { get; }
Property Value
ImagePartSize
Gets or sets the maximum height in pixels of an image part in HTML to Image converter
public int ImagePartSize { get; set; }
Property Value
ImpersonationOptions
The impersonation options applied during navigation in HTML to Image converter
public ImpersonationOptions ImpersonationOptions { get; }
Property Value
InitialHtmlViewerHeight
Gets or sets the initial height in pixels of the HTML viewer in HTML to Image converter. This value of this property is ignored if the HtmlViewerHeight property is set
public int InitialHtmlViewerHeight { get; set; }
Property Value
InterruptSlowJavaScript
Gets or sets a flag indicating if the slow JavaScript script should be interrupted in HTML to Image converter. The default value is false and the scripts are not interrupted
public bool InterruptSlowJavaScript { get; set; }
Property Value
JavaScriptEnabled
A flag indicating if JavaScript execution is enabled in HTML to Image converter. The default value is true
public bool JavaScriptEnabled { get; set; }
Property Value
LicenseKey
Gets or sets the license key string received from the vendor in HTML to Image converter. If this property is null the converter will automatically enter in evaluation mode and a demo watermark will be displayed on the generated image.
public string LicenseKey { get; set; }
Property Value
LocalFilesAccessEnabled
Gets or sets a flag indicating if the access to local files is enabled in the HTML to Image converter. The default value is true
public bool LocalFilesAccessEnabled { get; set; }
Property Value
ManualTriggeringConversionDelay
An additional time in seconds to wait after manual triggering before starting the rendering in HTML to Image converter. Default value is 2.
public int ManualTriggeringConversionDelay { get; set; }
Property Value
MaxHtmlViewerHeight
Gets or sets the maximum height in pixels to be rendered from the HTML document by the HTML to Image converter. The default value is 0 and the entire HTML document is rendered
public int MaxHtmlViewerHeight { get; set; }
Property Value
MediaType
Gets or sets the media type of the HTML document used by the HTML to Image converter. The default media type is 'screen'. If you set this property with 'print' then the CSS properties defined in '@media print' rule will be used to render the document
public string MediaType { get; set; }
Property Value
MinHtmlViewerHeight
Gets or sets the minimum height in pixels to be rendered from HTML document by the HTML to Image converter. This value of this property is ignored if the HtmlViewerHeight property is set
public int MinHtmlViewerHeight { get; set; }
Property Value
NavigationTimeout
The HTML to Image converter navigation timeout in seconds. Default value is 60.
public int NavigationTimeout { get; set; }
Property Value
NavigatorUserAgent
The custom user agent to be used when accessing the HTML page. When this property is null or empty the default user agent is used
public string NavigatorUserAgent { get; set; }
Property Value
PersistentHttpRequestHeaders
The PersistentHttpRequestHeaders property can be set on true to instruct the HTML to Image converter to send the custom headers defined by the HttpRequestHeaders property each time an external resource (image, css, etc) referenced by the web page is requested. The default value of this property is true and the custom headers are automatically sent to the web server when the web page resources are requested.
public bool PersistentHttpRequestHeaders { get; set; }
Property Value
PrerenderEnabled
Gets or sets a flag indicating if the HTML to Image converter should perform a pre-rendering. The default value is false
public bool PrerenderEnabled { get; set; }
Property Value
ProxyOptions
Gets a reference to an object encapsulating the proxy options used by HTML to Image converter to access the HTML document to convert.
public ProxyOptions ProxyOptions { get; }
Property Value
RenderedHtmlElementSelector
Get or set the CSS selector of the HTML element to be rendered by the HTML to Image converter. If the selector selects multiple HTML elements, only the the first one will be converted. The CSS selector is case sensitive. If this property is not set then the entire HTML document is rendered
public string RenderedHtmlElementSelector { get; set; }
Property Value
SvgFontsEnabled
Gets or sets a flag indicating if the SVG fonts are enabled in HTML during HTML to Image conversion. The default value is true
public bool SvgFontsEnabled { get; set; }
Property Value
TiledImageEnabled
A flag indicating if the image captured by converter is tiled. The default value is true
public bool TiledImageEnabled { get; set; }
Property Value
TransparentBackground
Gets or sets a flag indicating if the resulted image will have a transparent background when converting a HTML document without a defined background color or image. This property is false by default
public bool TransparentBackground { get; set; }
Property Value
TriggeringMode
The conversion triggering mode used by the HTML to Image converter. The default value is ConversionDelay.
public TriggeringMode TriggeringMode { get; set; }
Property Value
WebFontsEnabled
Gets or sets a flag indicating if the Web Fonts are enabled in HTML during the HTML to Image conversion. The default value is true
public bool WebFontsEnabled { get; set; }
Property Value
XPSupplementalLanguages
A flag in HTML to Image converter indicating if the supplemental languages (complex script, right-to-left, East Asian) support was enabled in Windows XP Regional and Language Options. The default value is false.
public bool XPSupplementalLanguages { get; set; }
Property Value
Methods
ConvertHtml(string, string, ImageFormat)
Converts a HTML string to an image having the given format using a base URL to resolve external resources and returns the rendered image into a memory buffer
public byte[] ConvertHtml(string htmlString, string baseUrl, ImageFormat format)
Parameters
htmlString
stringThe HTML string to convert to image
baseUrl
stringThe base URL used to determine the full URL of the external resources like images, CSS, JavaScript and Web Font files referenced by relative URLs in HTML
format
ImageFormatThe image format
Returns
- byte[]
A memory buffer containing the the generated image
ConvertHtmlFile(string, ImageFormat)
Converts a HTML file to an image having the given format and returns the rendered image into a memory buffer
public byte[] ConvertHtmlFile(string htmlFilePath, ImageFormat format)
Parameters
htmlFilePath
stringThe full path of the HTML file to convert to image
format
ImageFormatThe image format
Returns
- byte[]
A memory buffer containing the the generated image
ConvertHtmlFileToFile(string, ImageFormat, string)
Converts a HTML file to an image having the given format and writes the rendered image into a file
public void ConvertHtmlFileToFile(string htmlFilePath, ImageFormat format, string outFile)
Parameters
htmlFilePath
stringThe full path of the HTML file to convert to image
format
ImageFormatThe image format
outFile
stringThe full path of the file where to write the rendered image
ConvertHtmlStream(Stream, Encoding, string, ImageFormat)
Converts the HTML string read from a stream to an image having the given format using a base URL to resolve external resources and returns the rendered image into a memory buffer
public byte[] ConvertHtmlStream(Stream htmlStream, Encoding textEncoding, string baseUrl, ImageFormat format)
Parameters
htmlStream
StreamThe stream containing the HTML string to convert to image
textEncoding
EncodingThe stream text encoding
baseUrl
stringThe base URL used to determine the full URL of the external resources like images, CSS, JavaScript and Web Font files referenced by relative URLs in HTML
format
ImageFormatThe image format
Returns
- byte[]
A memory buffer containing the the generated image
ConvertHtmlStreamToFile(Stream, Encoding, string, ImageFormat, string)
to resolve external resources and writes the rendered image into a fileConverts the HTML string read from a stream to an image having the given format using a base URL
public void ConvertHtmlStreamToFile(Stream htmlStream, Encoding textEncoding, string baseUrl, ImageFormat format, string outFile)
Parameters
htmlStream
StreamThe stream containing the HTML string to convert to image
textEncoding
EncodingThe stream text encoding
baseUrl
stringThe base URL used to determine the full URL of the external resources like images, CSS, JavaScript and Web Font files referenced by relative URLs in HTML
format
ImageFormatThe image format
outFile
stringThe full path of the file where to write the rendered image
ConvertHtmlToFile(string, string, ImageFormat, string)
Converts a HTML string to an image having the given format using a base URL to resolve external resources and writes the rendered image into a file
public void ConvertHtmlToFile(string htmlString, string baseUrl, ImageFormat format, string outFile)
Parameters
htmlString
stringThe HTML string to be convert to image
baseUrl
stringThe URL base of the page
format
ImageFormatThe image format
outFile
stringThe full path of the file where to write the rendered image
ConvertHtmlToImageObject(string, string)
Converts a HTML string to an System.Drawing.Image object using a base URL to resolve external resources
public Image ConvertHtmlToImageObject(string htmlString, string baseUrl)
Parameters
htmlString
stringThe HTML string to convert to image
baseUrl
stringThe base URL used to determine the full URL of the external resources like images, CSS, JavaScript and Web Font files referenced by relative URLs in HTML
Returns
- Image
The created System.Drawing.Image object
ConvertHtmlToImageTiles(string, string)
Converts a HTML string to a set of System.Drawing.Image objects using a base URL to resolve external resources. The image is tiled to avoid working with very large images in memory
public Image[] ConvertHtmlToImageTiles(string htmlString, string baseUrl)
Parameters
htmlString
stringThe HTML string to convert to image
baseUrl
stringThe base URL used to determine the full URL of the external resources like images, CSS, JavaScript and Web Font files referenced by relative URLs in HTML
Returns
- Image[]
The rendered System.Drawing.Image objects
ConvertHtmlToImageTiles(string, string, string)
Converts a HTML string to a set of System.Drawing.Image objects using a base URL to resolve external resources and an internal links base URL. The image is tiled to avoid working with very large images in memory
public Image[] ConvertHtmlToImageTiles(string htmlString, string baseUrl, string internalLinksBaseUrl)
Parameters
htmlString
stringThe HTML string to convert to image
baseUrl
stringThe base URL used to determine the full URL of the external resources like images, CSS, JavaScript and Web Font files referenced by relative URLs in HTML
internalLinksBaseUrl
stringThe full URL of the HTML document referenced by the internal links from the HTML string
Returns
- Image[]
The created System.Drawing.Image objects
ConvertUrl(string, ImageFormat)
Converts an URL to an image having the given image format and returns the rendered image into a memory buffer
public byte[] ConvertUrl(string url, ImageFormat format)
Parameters
url
stringThe URL of the HTML document to convert to image. The full path of a HTML file in the local file system is accepted as an URL if necessary
format
ImageFormatThe image format
Returns
- byte[]
A memory buffer containing the the generated image
ConvertUrlToFile(string, ImageFormat, string)
Converts an URL to an image having the given format and writes the rendered image into a file
public void ConvertUrlToFile(string url, ImageFormat format, string outFile)
Parameters
url
stringThe URL of the HTML document to convert to image. The full path of a HTML file in the local file system is accepted as an URL if necessary
format
ImageFormatThe image format
outFile
stringThe full path of the file where to write the rendered image
ConvertUrlToImageObject(string)
Converts an URL to an System.Drawing.Image object
public Image ConvertUrlToImageObject(string url)
Parameters
url
stringThe URL of the HTML document to convert to image. The full path of a HTML file in the local file system is accepted as an URL if necessary
Returns
- Image
The created System.Drawing.Image object
ConvertUrlToImageTiles(string)
Converts an URL to a set of System.Drawing.Image objects. The image is tiled to avoid working with very large images in memory
public Image[] ConvertUrlToImageTiles(string url)
Parameters
url
stringThe URL of the HTML document to convert to image. The full path of a HTML file in the local file system is accepted as an URL if necessary
Returns
- Image[]
The created System.Drawing.Image objects