skip navigation
  • Product Bundles

    DevCraft

    All Telerik .NET tools and Kendo UI JavaScript components in one package. Now enhanced with:

    • AI Coding Assistants
    • Embedded Reporting
    • Document Processing Libraries
    • SSO Account Sign-in

    Web

    Kendo UI UI for Angular UI for Vue UI for jQuery KendoReact UI for Blazor UI for ASP.NET Core UI for ASP.NET MVC UI for ASP.NET AJAX

    Mobile

    UI for .NET MAUI

    Document Management

    Telerik Document Processing

    Desktop

    UI for .NET MAUI UI for WinUI UI for WinForms UI for WPF

    Reporting

    Telerik Reporting Telerik Report Server

    Testing & Mocking

    Test Studio Telerik JustMock

    CMS

    Sitefinity

    AI Productivity Tools

    AI Coding Assistants

    UI/UX Tools

    ThemeBuilder Design System Kit Templates and Building Blocks

    Debugging

    Fiddler Fiddler Everywhere Fiddler Classic Fiddler Everywhere Reporter FiddlerCore

    Free Tools

    KendoReact Free VB.NET to C# Converter Testing Framework
    View all products
  • Overview
  • Demos
    • What's New
    • Roadmap
    • Release History
  • Support and Learning

    • Support and Learning Hub
    • First Steps
    • Docs
    • Demos
    • Virtual Classroom
    • Forums
    • Videos
    • Blogs
    • Accessibility
    • Submit a Ticket

    Productivity and Design Tools

    • Visual Studio Extensions
    • Visual Studio Templates
    • Embedded Reporting
  • Pricing
  • Shopping cart
    • Account Overview
    • Your Licenses
    • Downloads
    • Support Center
    • Forum Profile
    • Payment Methods
    • Edit Profile
    • Log out
  • Login
  • Contact Us
  • Try now

Class HtmlRender

Standalone static class for simple and direct HTML rendering.
For low-level control and performance consider using HtmlContainer.

Inheritance
System.Object
HtmlRender
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: TheArtOfDev.HtmlRenderer.WinForms
Assembly: Telerik.WinControls.RadMap.dll

Syntax

public static class HtmlRender
Remarks

GDI vs. GDI+ text rendering
Windows supports two text rendering technologies: GDI and GDI+.
GDI is older, has better performance and looks better on standard monitors but doesn't support alpha channel for transparency.
GDI+ is newer, device independent so work better for printers but is slower and looks worse on monitors.
HtmlRender supports both GDI and GDI+ text rendering to accommodate different needs, GDI+ text rendering methods have "GdiPlus" suffix in their name where GDI do not.

Rendering to image
See https://htmlrenderer.codeplex.com/wikipage?title=Image%20generation
Because of GDI text rendering issue with alpha channel clear type text rendering rendering to image requires special handling.
Solid color background - generate an image where the background is filled with solid color and all the html is rendered on top of the background color, GDI text rendering will be used. (RenderToImage method where the first argument is html string)
Image background - render html on top of existing image with whatever currently exist but it cannot have transparent pixels, GDI text rendering will be used. (RenderToImage method where the first argument is Image object)
Transparent background - render html to empty image using GDI+ text rendering, the generated image can be transparent. Text rendering can be controlled using System.Drawing.Text.TextRenderingHint, note that System.Drawing.Text.TextRenderingHint.ClearTypeGridFit doesn't render well on transparent background. (RenderToImageGdiPlus method)

Overwrite stylesheet resolution
Exposed by optional "stylesheetLoad" delegate argument.
Invoked when a stylesheet is about to be loaded by file path or URL in 'link' element.
Allows to overwrite the loaded stylesheet by providing the stylesheet data manually, or different source (file or URL) to load from.
Example: The stylesheet 'href' can be non-valid URI string that is interpreted in the overwrite delegate by custom logic to pre-loaded stylesheet object
If no alternative data is provided the original source will be used.

Overwrite image resolution
Exposed by optional "imageLoad" delegate argument.
Invoked when an image is about to be loaded by file path, URL or inline data in 'img' element or background-image CSS style.
Allows to overwrite the loaded image by providing the image object manually, or different source (file or URL) to load from.
Example: image 'src' can be non-valid string that is interpreted in the overwrite delegate by custom logic to resource image object
Example: image 'src' in the html is relative - the overwrite intercepts the load and provide full source URL to load the image from
Example: image download requires authentication - the overwrite intercepts the load, downloads the image to disk using custom code and provide file path to load the image from.
If no alternative data is provided the original source will be used.
Note: Cannot use asynchronous scheme overwrite scheme.

Examples

Simple rendering
HtmlRender.Render(g, "<div>Hello <b>World</b></div>");
HtmlRender.Render(g, "<div>Hello <b>World</b></div>", 10, 10, 500, CssData.Parse("body {font-size: 20px}")");

Image rendering
HtmlRender.RenderToImage("<div>Hello <b>World</b></div>", new Size(600,400));
HtmlRender.RenderToImage("<div>Hello <b>World</b></div>", 600);
HtmlRender.RenderToImage(existingImage, "<div>Hello <b>World</b></div>");

Methods

AddFontFamily(FontFamily)

Adds a font family to be used in html rendering.
The added font will be used by all rendering function including HtmlContainer and all WinForms controls.

Declaration
public static void AddFontFamily(FontFamily fontFamily)
Parameters
System.Drawing.FontFamily fontFamily

The font family to add.

Remarks

The given font family instance must be remain alive while the renderer is in use.
If loaded to System.Drawing.Text.PrivateFontCollection then the collection must be alive.
If loaded from file then the file must not be deleted.

AddFontFamilyMapping(String, String)

Adds a font mapping from fromFamily to toFamily iff the fromFamily is not found.
When the fromFamily font is used in rendered html and is not found in existing fonts (installed or added) it will be replaced by toFamily.

Declaration
public static void AddFontFamilyMapping(string fromFamily, string toFamily)
Parameters
System.String fromFamily

the font family to replace

System.String toFamily

the font family to replace with

Remarks

This fonts mapping can be used as a fallback in case the requested font is not installed in the client system.

Measure(Graphics, String, Single, CssData, EventHandler<HtmlStylesheetLoadEventArgs>, EventHandler<HtmlImageLoadEventArgs>)

Measure the size (width and height) required to draw the given html under given max width restriction.
If no max width restriction is given the layout will use the maximum possible width required by the content, it can be the longest text line or full image width.
Use GDI text rendering, note System.Drawing.Graphics.TextRenderingHint has no effect.

Declaration
public static SizeF Measure(Graphics g, string html, float maxWidth = 0F, CssData cssData = null, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
Parameters
System.Drawing.Graphics g

Device to use for measure

System.String html

HTML source to render

System.Single maxWidth

optional: bound the width of the html to render in (default - 0, unlimited)

CssData cssData

optional: the style to use for html rendering (default - use W3 default style)

System.EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad

optional: can be used to overwrite stylesheet resolution logic

System.EventHandler<HtmlImageLoadEventArgs> imageLoad

optional: can be used to overwrite image resolution logic

Returns
System.Drawing.SizeF

the size required for the html

MeasureGdiPlus(Graphics, String, Single, CssData, EventHandler<HtmlStylesheetLoadEventArgs>, EventHandler<HtmlImageLoadEventArgs>)

Measure the size (width and height) required to draw the given html under given max width restriction.
If no max width restriction is given the layout will use the maximum possible width required by the content, it can be the longest text line or full image width.
Use GDI+ text rending, use System.Drawing.Graphics.TextRenderingHint to control text rendering.

Declaration
public static SizeF MeasureGdiPlus(Graphics g, string html, float maxWidth = 0F, CssData cssData = null, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
Parameters
System.Drawing.Graphics g

Device to use for measure

System.String html

HTML source to render

System.Single maxWidth

optional: bound the width of the html to render in (default - 0, unlimited)

CssData cssData

optional: the style to use for html rendering (default - use W3 default style)

System.EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad

optional: can be used to overwrite stylesheet resolution logic

System.EventHandler<HtmlImageLoadEventArgs> imageLoad

optional: can be used to overwrite image resolution logic

Returns
System.Drawing.SizeF

the size required for the html

ParseStyleSheet(String, Boolean)

Parse the given stylesheet to CssData object.
If combineWithDefault is true the parsed css blocks are added to the default css data (as defined by W3), merged if class name already exists. If false only the data in the given stylesheet is returned.

Declaration
public static CssData ParseStyleSheet(string stylesheet, bool combineWithDefault = true)
Parameters
System.String stylesheet

the stylesheet source to parse

System.Boolean combineWithDefault

true - combine the parsed css data with default css data, false - return only the parsed css data

Returns
CssData

the parsed css data

See Also
http://www.w3.org/TR/CSS21/sample.html

Render(Graphics, String, PointF, SizeF, CssData, EventHandler<HtmlStylesheetLoadEventArgs>, EventHandler<HtmlImageLoadEventArgs>)

Renders the specified HTML source on the specified location and max size restriction.
Use GDI text rendering, note System.Drawing.Graphics.TextRenderingHint has no effect.
If maxSize.Width is zero the html will use all the required width, otherwise it will perform line wrap as specified in the html
If maxSize.Height is zero the html will use all the required height, otherwise it will clip at the given max height not rendering the html below it.
Returned is the actual width and height of the rendered html.

Declaration
public static SizeF Render(Graphics g, string html, PointF location, SizeF maxSize, CssData cssData = null, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
Parameters
System.Drawing.Graphics g

Device to render with

System.String html

HTML source to render

System.Drawing.PointF location

the top-left most location to start render the html at

System.Drawing.SizeF maxSize

the max size of the rendered html (if height above zero it will be clipped)

CssData cssData

optional: the style to use for html rendering (default - use W3 default style)

System.EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad

optional: can be used to overwrite stylesheet resolution logic

System.EventHandler<HtmlImageLoadEventArgs> imageLoad

optional: can be used to overwrite image resolution logic

Returns
System.Drawing.SizeF

the actual size of the rendered html

Render(Graphics, String, Single, Single, Single, CssData, EventHandler<HtmlStylesheetLoadEventArgs>, EventHandler<HtmlImageLoadEventArgs>)

Renders the specified HTML source on the specified location and max width restriction.
Use GDI text rendering, note System.Drawing.Graphics.TextRenderingHint has no effect.
If maxWidth is zero the html will use all the required width, otherwise it will perform line wrap as specified in the html
Returned is the actual width and height of the rendered html.

Declaration
public static SizeF Render(Graphics g, string html, float left = 0F, float top = 0F, float maxWidth = 0F, CssData cssData = null, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
Parameters
System.Drawing.Graphics g

Device to render with

System.String html

HTML source to render

System.Single left

optional: the left most location to start render the html at (default - 0)

System.Single top

optional: the top most location to start render the html at (default - 0)

System.Single maxWidth

optional: bound the width of the html to render in (default - 0, unlimited)

CssData cssData

optional: the style to use for html rendering (default - use W3 default style)

System.EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad

optional: can be used to overwrite stylesheet resolution logic

System.EventHandler<HtmlImageLoadEventArgs> imageLoad

optional: can be used to overwrite image resolution logic

Returns
System.Drawing.SizeF

the actual size of the rendered html

RenderGdiPlus(Graphics, String, PointF, SizeF, CssData, EventHandler<HtmlStylesheetLoadEventArgs>, EventHandler<HtmlImageLoadEventArgs>)

Renders the specified HTML source on the specified location and max size restriction.
Use GDI+ text rending, use System.Drawing.Graphics.TextRenderingHint to control text rendering.
If maxSize.Width is zero the html will use all the required width, otherwise it will perform line wrap as specified in the html
If maxSize.Height is zero the html will use all the required height, otherwise it will clip at the given max height not rendering the html below it.
Returned is the actual width and height of the rendered html.

Declaration
public static SizeF RenderGdiPlus(Graphics g, string html, PointF location, SizeF maxSize, CssData cssData = null, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
Parameters
System.Drawing.Graphics g

Device to render with

System.String html

HTML source to render

System.Drawing.PointF location

the top-left most location to start render the html at

System.Drawing.SizeF maxSize

the max size of the rendered html (if height above zero it will be clipped)

CssData cssData

optional: the style to use for html rendering (default - use W3 default style)

System.EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad

optional: can be used to overwrite stylesheet resolution logic

System.EventHandler<HtmlImageLoadEventArgs> imageLoad

optional: can be used to overwrite image resolution logic

Returns
System.Drawing.SizeF

the actual size of the rendered html

RenderGdiPlus(Graphics, String, Single, Single, Single, CssData, EventHandler<HtmlStylesheetLoadEventArgs>, EventHandler<HtmlImageLoadEventArgs>)

Renders the specified HTML source on the specified location and max size restriction.
Use GDI+ text rending, use System.Drawing.Graphics.TextRenderingHint to control text rendering.
If maxWidth is zero the html will use all the required width, otherwise it will perform line wrap as specified in the html
Returned is the actual width and height of the rendered html.

Declaration
public static SizeF RenderGdiPlus(Graphics g, string html, float left = 0F, float top = 0F, float maxWidth = 0F, CssData cssData = null, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
Parameters
System.Drawing.Graphics g

Device to render with

System.String html

HTML source to render

System.Single left

optional: the left most location to start render the html at (default - 0)

System.Single top

optional: the top most location to start render the html at (default - 0)

System.Single maxWidth

optional: bound the width of the html to render in (default - 0, unlimited)

CssData cssData

optional: the style to use for html rendering (default - use W3 default style)

System.EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad

optional: can be used to overwrite stylesheet resolution logic

System.EventHandler<HtmlImageLoadEventArgs> imageLoad

optional: can be used to overwrite image resolution logic

Returns
System.Drawing.SizeF

the actual size of the rendered html

RenderToImage(Image, String, PointF, SizeF, CssData, EventHandler<HtmlStylesheetLoadEventArgs>, EventHandler<HtmlImageLoadEventArgs>)

Renders the specified HTML on top of the given image.
image will contain the rendered html in it on top of original content.
image must not contain transparent pixels as it will corrupt the rendered html text.
See "Rendering to image" remarks section on HtmlRender.

Declaration
public static void RenderToImage(Image image, string html, PointF location, SizeF maxSize, CssData cssData = null, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
Parameters
System.Drawing.Image image

the image to render the html on

System.String html

HTML source to render

System.Drawing.PointF location

the top-left most location to start render the html at

System.Drawing.SizeF maxSize

the max size of the rendered html (if height above zero it will be clipped)

CssData cssData

optional: the style to use for html rendering (default - use W3 default style)

System.EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad

optional: can be used to overwrite stylesheet resolution logic

System.EventHandler<HtmlImageLoadEventArgs> imageLoad

optional: can be used to overwrite image resolution logic

RenderToImage(Image, String, PointF, CssData, EventHandler<HtmlStylesheetLoadEventArgs>, EventHandler<HtmlImageLoadEventArgs>)

Renders the specified HTML on top of the given image.
image will contain the rendered html in it on top of original content.
image must not contain transparent pixels as it will corrupt the rendered html text.
The HTML will be layout by the given image size but may be clipped if cannot fit.
See "Rendering to image" remarks section on HtmlRender.

Declaration
public static void RenderToImage(Image image, string html, PointF location = null, CssData cssData = null, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
Parameters
System.Drawing.Image image

the image to render the html on

System.String html

HTML source to render

System.Drawing.PointF location

optional: the top-left most location to start render the html at (default - 0,0)

CssData cssData

optional: the style to use for html rendering (default - use W3 default style)

System.EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad

optional: can be used to overwrite stylesheet resolution logic

System.EventHandler<HtmlImageLoadEventArgs> imageLoad

optional: can be used to overwrite image resolution logic

RenderToImage(String, Size, Color, CssData, EventHandler<HtmlStylesheetLoadEventArgs>, EventHandler<HtmlImageLoadEventArgs>)

Renders the specified HTML into a new image of the requested size.
The HTML will be layout by the given size but will be clipped if cannot fit.

Limitation: The image cannot have transparent background, by default it will be white.
See "Rendering to image" remarks section on HtmlRender.

Declaration
public static Image RenderToImage(string html, Size size, Color backgroundColor = null, CssData cssData = null, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
Parameters
System.String html

HTML source to render

System.Drawing.Size size

The size of the image to render into, layout html by width and clipped by height

System.Drawing.Color backgroundColor

optional: the color to fill the image with (default - white)

CssData cssData

optional: the style to use for html rendering (default - use W3 default style)

System.EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad

optional: can be used to overwrite stylesheet resolution logic

System.EventHandler<HtmlImageLoadEventArgs> imageLoad

optional: can be used to overwrite image resolution logic

Returns
System.Drawing.Image

the generated image of the html

Exceptions
System.ArgumentOutOfRangeException

if backgroundColor is System.Drawing.Color.Transparent

RenderToImage(String, Size, Size, Color, CssData, EventHandler<HtmlStylesheetLoadEventArgs>, EventHandler<HtmlImageLoadEventArgs>)

Renders the specified HTML into a new image of unknown size that will be determined by min/max width/height and HTML layout.
If maxSize.Width is zero the html will use all the required width, otherwise it will perform line wrap as specified in the html
If maxSize.Height is zero the html will use all the required height, otherwise it will clip at the given max height not rendering the html below it.
If minSize (Width/Height) is above zero the rendered image will not be smaller than the given min size.

Limitation: The image cannot have transparent background, by default it will be white.
See "Rendering to image" remarks section on HtmlRender.

Declaration
public static Image RenderToImage(string html, Size minSize, Size maxSize, Color backgroundColor = null, CssData cssData = null, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
Parameters
System.String html

HTML source to render

System.Drawing.Size minSize

optional: the min size of the rendered html (zero - not limit the width/height)

System.Drawing.Size maxSize

optional: the max size of the rendered html, if not zero and html cannot be layout within the limit it will be clipped (zero - not limit the width/height)

System.Drawing.Color backgroundColor

optional: the color to fill the image with (default - white)

CssData cssData

optional: the style to use for html rendering (default - use W3 default style)

System.EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad

optional: can be used to overwrite stylesheet resolution logic

System.EventHandler<HtmlImageLoadEventArgs> imageLoad

optional: can be used to overwrite image resolution logic

Returns
System.Drawing.Image

the generated image of the html

Exceptions
System.ArgumentOutOfRangeException

if backgroundColor is System.Drawing.Color.Transparent

RenderToImage(String, Int32, Int32, Color, CssData, EventHandler<HtmlStylesheetLoadEventArgs>, EventHandler<HtmlImageLoadEventArgs>)

Renders the specified HTML into a new image of unknown size that will be determined by max width/height and HTML layout.
If maxWidth is zero the html will use all the required width, otherwise it will perform line wrap as specified in the html
If maxHeight is zero the html will use all the required height, otherwise it will clip at the given max height not rendering the html below it.

Limitation: The image cannot have transparent background, by default it will be white.
See "Rendering to image" remarks section on HtmlRender.

Declaration
public static Image RenderToImage(string html, int maxWidth = 0, int maxHeight = 0, Color backgroundColor = null, CssData cssData = null, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
Parameters
System.String html

HTML source to render

System.Int32 maxWidth

optional: the max width of the rendered html, if not zero and html cannot be layout within the limit it will be clipped

System.Int32 maxHeight

optional: the max height of the rendered html, if not zero and html cannot be layout within the limit it will be clipped

System.Drawing.Color backgroundColor

optional: the color to fill the image with (default - white)

CssData cssData

optional: the style to use for html rendering (default - use W3 default style)

System.EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad

optional: can be used to overwrite stylesheet resolution logic

System.EventHandler<HtmlImageLoadEventArgs> imageLoad

optional: can be used to overwrite image resolution logic

Returns
System.Drawing.Image

the generated image of the html

Exceptions
System.ArgumentOutOfRangeException

if backgroundColor is System.Drawing.Color.Transparent

RenderToImageGdiPlus(String, Size, Size, TextRenderingHint, CssData, EventHandler<HtmlStylesheetLoadEventArgs>, EventHandler<HtmlImageLoadEventArgs>)

Renders the specified HTML into a new image of unknown size that will be determined by min/max width/height and HTML layout.
If maxSize.Width is zero the html will use all the required width, otherwise it will perform line wrap as specified in the html
If maxSize.Height is zero the html will use all the required height, otherwise it will clip at the given max height not rendering the html below it.
If minSize (Width/Height) is above zero the rendered image will not be smaller than the given min size.
The generated image have transparent background that the html is rendered on.
GDI+ text rending can be controlled by providing System.Drawing.Text.TextRenderingHint.
See "Rendering to image" remarks section on HtmlRender.

Declaration
public static Image RenderToImageGdiPlus(string html, Size minSize, Size maxSize, TextRenderingHint textRenderingHint, CssData cssData = null, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
Parameters
System.String html

HTML source to render

System.Drawing.Size minSize

optional: the min size of the rendered html (zero - not limit the width/height)

System.Drawing.Size maxSize

optional: the max size of the rendered html, if not zero and html cannot be layout within the limit it will be clipped (zero - not limit the width/height)

System.Drawing.Text.TextRenderingHint textRenderingHint

optional: (default - SingleBitPerPixelGridFit)

CssData cssData

optional: the style to use for html rendering (default - use W3 default style)

System.EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad

optional: can be used to overwrite stylesheet resolution logic

System.EventHandler<HtmlImageLoadEventArgs> imageLoad

optional: can be used to overwrite image resolution logic

Returns
System.Drawing.Image

the generated image of the html

RenderToImageGdiPlus(String, Size, TextRenderingHint, CssData, EventHandler<HtmlStylesheetLoadEventArgs>, EventHandler<HtmlImageLoadEventArgs>)

Renders the specified HTML into a new image of the requested size.
The HTML will be layout by the given size but will be clipped if cannot fit.
The generated image have transparent background that the html is rendered on.
GDI+ text rending can be controlled by providing System.Drawing.Text.TextRenderingHint.
See "Rendering to image" remarks section on HtmlRender.

Declaration
public static Image RenderToImageGdiPlus(string html, Size size, TextRenderingHint textRenderingHint, CssData cssData = null, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
Parameters
System.String html

HTML source to render

System.Drawing.Size size

The size of the image to render into, layout html by width and clipped by height

System.Drawing.Text.TextRenderingHint textRenderingHint

optional: (default - SingleBitPerPixelGridFit)

CssData cssData

optional: the style to use for html rendering (default - use W3 default style)

System.EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad

optional: can be used to overwrite stylesheet resolution logic

System.EventHandler<HtmlImageLoadEventArgs> imageLoad

optional: can be used to overwrite image resolution logic

Returns
System.Drawing.Image

the generated image of the html

RenderToImageGdiPlus(String, Int32, Int32, TextRenderingHint, CssData, EventHandler<HtmlStylesheetLoadEventArgs>, EventHandler<HtmlImageLoadEventArgs>)

Renders the specified HTML into a new image of unknown size that will be determined by max width/height and HTML layout.
If maxWidth is zero the html will use all the required width, otherwise it will perform line wrap as specified in the html
If maxHeight is zero the html will use all the required height, otherwise it will clip at the given max height not rendering the html below it.
The generated image have transparent background that the html is rendered on.
GDI+ text rending can be controlled by providing System.Drawing.Text.TextRenderingHint.
See "Rendering to image" remarks section on HtmlRender.

Declaration
public static Image RenderToImageGdiPlus(string html, int maxWidth = 0, int maxHeight = 0, TextRenderingHint textRenderingHint, CssData cssData = null, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
Parameters
System.String html

HTML source to render

System.Int32 maxWidth

optional: the max width of the rendered html, if not zero and html cannot be layout within the limit it will be clipped

System.Int32 maxHeight

optional: the max height of the rendered html, if not zero and html cannot be layout within the limit it will be clipped

System.Drawing.Text.TextRenderingHint textRenderingHint

optional: (default - SingleBitPerPixelGridFit)

CssData cssData

optional: the style to use for html rendering (default - use W3 default style)

System.EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad

optional: can be used to overwrite stylesheet resolution logic

System.EventHandler<HtmlImageLoadEventArgs> imageLoad

optional: can be used to overwrite image resolution logic

Returns
System.Drawing.Image

the generated image of the html

RenderToMetafile(String, Single, Single, Single, CssData, EventHandler<HtmlStylesheetLoadEventArgs>, EventHandler<HtmlImageLoadEventArgs>)

Declaration
public static Metafile RenderToMetafile(string html, float left = 0F, float top = 0F, float maxWidth = 0F, CssData cssData = null, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
Parameters
System.String html

System.Single left

System.Single top

System.Single maxWidth

CssData cssData

System.EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad

System.EventHandler<HtmlImageLoadEventArgs> imageLoad

Returns
System.Drawing.Imaging.Metafile

Getting Started
  • Install Now
  • Demos
  • Step-by-Step Tutorial
  • Sample Applications
  • SDK Samples
  • Visual Studio Extensions
Support Resources
  • Code Library
  • Knowledge Base
  • Videos
Community
  • Forums
  • Blogs
  • Feedback Portal
  • Document Processing Feedback Portal

Copyright © 2018 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.