HTML to Image Generator for .NET C# WkHtmlToImage Wrapper


features

  • Render HTML pages (with floating divs, CSS, images, javascript code) to image (jpg,png) canvas with WebKit engine (based on WkHtmlToImage tool)
  • Convert HTML to image (jpg,png) from any .NET application (including ASP.NET WebForms, MVC)
  • Generate web page thumbnail (web page screenshot)
  • Render SVG to PNG/Jpeg (charts, diagrams) on the server side
  • Easy to use WkHtmlToImage C# wrapper library: all you need is one assembly.
    In case of .NET Core wkhtmltoimage should be deployed separately.
  • Usage examples (C#):
    • WebForms: web page preview (take a screenshot of a web page)
    • MVC.NET samples:
      • export GoogleChart SVG to image
      • generate Barcode image from HTML+Javascript
  • Looking for HTML to PDF converter? Try NReco.PdfGenerator

download and pricing

quick purchase process

  • 1 Choose a package
  • 2 Pay online Online payment methods
  • 3 Download the package
Need to perform HTML to image conversion from C# code and get similar to web browser rendering result? NReco.ImageGenerator is a right choice!

how to use

  1. Install NReco.ImageGenerator nuget package
  2. Render HTML to image with one line of C# code:
    var html = String.Format("<body>Hello world: {0}</body>",DateTime.Now);
    var htmlToImageConv = new NReco.ImageGenerator.HtmlToImageConverter();
    var jpegBytes = htmlToImageConv.GenerateImage(html, ImageFormat.Jpeg);
  3. That's all! Check out online documentation for additional options.
Feel free to contact us in case of any questions.

render HTML to image demo

Web page URL:
Notice: don't use intranet/extranet/VPN/local URLs (like 'localhost').
In most cases they are not accessible by our server and require authentication; ImageGenerator will able to convert these pages only when hosted on your server.
Get Web Page Thumbnail (Preview)

frequently asked questions

ImageGenerator can be used for FREE in single-deployment projects (websites, intranet/extranet) or applications for company's internal business purposes (redistributed only internally inside the company).

Commercial license is required for:
  • Applications for external redistribution (ISV) or multiple deployments
  • SaaS deployments
Note that support is NOT available for free users.
It is possible to include images by specifying their FULL URL or path (if they're on local filesystem). External CSS and javascript files are also supported.
ImageGenerator executes WkHtmlToImage command line tool in a separate process using System.Diagnostics.Process API and your app's hosting environment/platform should allow that.

WkHtmlToImage is based on QtWebKit 4.8 so it doesn't support modern CSS3 features (like flex/grid layout, ES2015 etc).

Component cannot be used (does NOT work) if wkhtmltoimage cannot be deployed (installed) and executed via System.Diagnostics.Process API: most shared ASP.NET hostings, UWP/Univeral Apps, mobile apps. Also this means that non-Windows environments are NOT supported by NReco.ImageGenerator nuget package and NReco.ImageGenerator.LT should be used instead (see below).

NET6/NET8+ apps
For cross-platform apps (Linux, Mac-OS, Docker images) another nuget NReco.ImageGenerator.LT should be used instead (C# API is the same). This version doesn't include wkhtmltopdf binaries so you need to deploy the latest wkhtmltoimage (builds for modern Linux are here) your target platform(s) with your .NET app separately.

LT build usage
The following C# code snippet illustrates how to initialize NReco.ImageGenerator.LT properly:
NReco.ImageGenerator.License.SetLicenseKey("your_id", "your_license_key");

var htmlToImg = new NReco.PdfGenerator.HtmlToImageConverter();

// for Linux/OS-X: "wkhtmltoimage"
htmlToImg.WkHtmlToImageExeName = "wkhtmltoimage.exe";
// specify where wkhtmltoimage binaries are installed/deployed
htmlToImg.ToolPath = "<path_to_folder_with_wkhtmltoimage>";
htmlToImg.GenerateImageFromFile("http://www.google.com", ImageFormat.Png, "google.png");
If you want to test LT nuget package you can contact support and ask for a demo key.
In some cases image generation fails with one of the following errors:
  • Exit with code 1 due to network error: ContentNotFoundError
  • Exit with code 1 due to network error: ProtocolUnknownError
  • Exit with code 1 due to network error: HostNotFoundError
This means that HTML template has external reference (js/css/image URL) that cannot be loaded by WkHtmlToImage. In most cases image can be generated anyway by specifying additional WkHtmlToImage parameter:
var htmlToImage = new HtmlToImageConverter();
htmlToImage.CustomArgs = " --load-media-error-handling ignore ";
NReco.ImageGenerator.LT is a .NET wrapper for wkhtmltoimage and this means that wkhtmltoimage should be included into your app's Docker image.
Normally NET8+ app Linux image is based on mcr.microsoft.com/dotnet/aspnet:8.0 (Debian 12 "bookworm"), to deploy wkhtmltoimage the following commands should be added into the 'Dockerfile':
RUN apt-get update && apt-get install -y --no-install-recommends wget ca-certificates fontconfig libc6 libfreetype6 libjpeg62-turbo libpng16-16 libssl3 libstdc++6 libx11-6 libxcb1 libxext6 libxrender1 xfonts-75dpi xfonts-base zlib1g
RUN wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-3/wkhtmltox_0.12.6.1-3.bookworm_amd64.deb
RUN dpkg -i wkhtmltox_0.12.6.1-3.bookworm_amd64.deb

Do NOT install wkhtmltoimage via apt-get install -y wkhtmltopdf because most likely you'll install legacy (old) version and possibly a wrong build (without 'patched' QT).

If you want to use Windows fonts (Arial, Times New Roman, Courier New etc) add these commands into 'Dockerfile':
RUN echo "deb http://deb.debian.org/debian bookworm contrib non-free" > /etc/apt/sources.list.d/contrib.list
RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections
RUN apt-get update -y && apt-get install -y --no-install-recommends ttf-mscorefonts-installer
RUN fc-cache -f -v

what's new

2020 Jun 15 v.1.2.0 changes:
  • wkhtmltoimage upgraded to 0.12.6 (released on 2020-Jun-11)
2019 Apr 03 v.1.1.3 changes:
  • fixed issue with exceptions inside AsyncStreamCopyTo
  • net20 target is not supported any more, minimal legacy target is net45
2018 Nov 23 v.1.1.2 changes:
  • added netstandard20 build (update affects only NReco.ImageGenerator.LT nuget package)
2017 Nov 23 v.1.1.1 changes:
  • fixed issue with ExecutionTimeout (didn't work)
  • added LogReceived event
2017 Mar 31 v.1.1.0 changes:
  • WkHtmlToImage tool upgraded to version 0.12.4 (released 2016-Nov-22)
  • all necessary VC++ Runtime 2015 dlls are included
  • now for ASP.NET apps wkhtmltoimage binaries are extracted to 'App_Data\wkhtmltoimage' by default
2015 Sep 10 v.1.0.3 changes:
  • hotfix for '(0) is invalid for Enum type 'ProcessPriorityClass' error
  • VC++ 2013 runtime libs (msvcp120.dll, msvcr120.dll) required by wkhtmltoimage.exe are included as embedded resources (no need to install VC++ 2013 redist)
2015 Aug 27 v.1.0.2 changes:
  • added ProcessPriority and ExecutionTimeout properties
  • added workaround for "Exit with code 1 due to network error" wkhtmltoimage issue: when "--load-error-handling" or "--load-media-error-handling" set to "ignore" (or "skip") wkhtmltoimage generates an image but exited with code = 1 and as result WkHtmlToImageException is thrown. Now this case is handled correctly and exception is not thrown.
  • now NReco.ImageGenerator.dll is a signed (strongly named) assembly
2015 Feb 02 v.1.0.1: Fixed issue with image format (was ignored)
2015 Jan 24 v.1.0: Initial ImageGenerator release based on WkHtmlToImage v.0.12.2.1

more components

  • HTML-to-PDF Generator

    .NET wrapper for WkHtmlToPdf utility that generates PDF reports by HTML template.

  • PDF-to-Image Renderer

    .NET wrapper for poppler tools that converts PDF pages to images or text (ASP.NET PDF viewer, PDF thumbnails, extract PDF text/images).