New to Telerik Reporting? Download free 30-day trial

Render Any HTML Tags and CSS Attributes in Reports

Environment

Product Progress® Telerik® Reporting
Rendering Format All Rendering Formats

Description

A frequently asked question is how to render HTML tags and CSS attributes that are not supported by HtmlTextBox item in reports. The most requested tags that can, currently, be displayed only through this article's workaround are the img and table HTML tags.

The workaround that this article will demonstrate is to render the HTML/CSS content as a Bitmap or Image in an User Function and then have that function invoked on the Value property of a PictureBox item.

Solution

  1. Create a .NET Framework Class Library project - Create a .NET class library using Visual Studio.
  2. Install the HtmlRenderer.WinForms NuGet package in the project.
  3. In the class library, create a static method that accepts the HTML string as parameters and returns an image from it using the HtmlRenderer.WinForms library's APIs:

    namespace UserFunctions
    {
        public class Functions
        {
            public static System.Drawing.Image HtmlToImage(string html)
            {
                return TheArtOfDev.HtmlRenderer.WinForms.HtmlRender.RenderToImage(html);
            }
        }
    }
    
  4. Build the project, then copy the project assembly as well as the HtmlRenderer.WinForms.dll assembly from the project's bin folder to the folder where the Report Designer exe is located, e.g. C:\Program Files (x86)\Progress\Telerik Reporting 2024 Q3\Report Designer.

  5. Open the Telerik.ReportDesigner.exe.config file and use the assemblyReferences Element to add references to the Class Library project's assembly and the HtmlRenderer.WinForms.dll assembly:

    <Telerik.Reporting>
        <AssemblyReferences>
            <add name="UserFunctions" />
            <add name="HtmlRenderer.WinForms" />
        </AssemblyReferences>
    </Telerik.Reporting>
    
  6. Start the Report Designer and open/create a report, then create a PictureBox item and set the following expression as its Value:

    = UserFunctions.Functions.HtmlToImage(HTML)

    In place of the HTML, you can use a field that returns the HTML string, a report parameter, or it can even be written inline with quotation marks.

Notes

To display a report that uses this approach in a separate application, the assembly of the Class Library project and the HtmlRenderer.WinForms.dll assembly should be referenced in the project where Reporting will be used - Configuration for the Report Viewer/Web Report Designer.

See Also

In this article