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
Image Generator FREE Binary pack
Examples, NO support, .NET Framework-only |
Download for Free |
Image Generator enterprise source code pack
Includes: component source code, extended license for redistribution and SaaS usage, license key for LT-version (.NET Core compatible), 1 year of email support and free updates |
$99 - Order Now |
quick purchase process
- 1 Choose a package
- 2 Pay online
- 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
- Install NReco.ImageGenerator nuget package
- 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);
- That's all! Check out online documentation for additional options.
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.
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.
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:
Commercial license is required for:
- Applications for external redistribution (ISV) or multiple deployments
- SaaS deployments
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
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:
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
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
Do NOT install wkhtmltoimage via
If you want to use Windows fonts (Arial, Times New Roman, Courier New etc) add these commands into 'Dockerfile':
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:
|
2019 Apr 03 |
v.1.1.3 changes:
|
2018 Nov 23 |
v.1.1.2 changes:
|
2017 Nov 23 |
v.1.1.1 changes:
|
2017 Mar 31 |
v.1.1.0 changes:
|
2015 Sep 10 |
v.1.0.3 changes:
|
2015 Aug 27 |
v.1.0.2 changes:
|
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).