CoreHtmlToImage 2.0.0

dotnet add package CoreHtmlToImage --version 2.0.0
                    
NuGet\Install-Package CoreHtmlToImage -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CoreHtmlToImage" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CoreHtmlToImage" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="CoreHtmlToImage" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CoreHtmlToImage --version 2.0.0
                    
#r "nuget: CoreHtmlToImage, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CoreHtmlToImage@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CoreHtmlToImage&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CoreHtmlToImage&version=2.0.0
                    
Install as a Cake Tool

CI NuGet

.NET Core HTML to Image Converter

Cross-platform .NET library that converts HTML strings or URLs to image bytes using headless Chromium (via PuppeteerSharp). Supports Windows, Linux, and macOS.

Installation

Install-Package CoreHtmlToImage

dotnet CLI:

dotnet add package CoreHtmlToImage

Note: On first use, PuppeteerSharp automatically downloads a compatible Chromium binary (~200MB, cached for subsequent runs).

Usage

await using var converter = new HtmlConverter();

// From HTML string
var bytes = await converter.FromHtmlStringAsync("<div><strong>Hello</strong> World!</div>");
File.WriteAllBytes("image.jpg", bytes);

// From URL
var bytes = await converter.FromUrlAsync("https://example.com");
File.WriteAllBytes("image.jpg", bytes);

Options

var options = new HtmlConverterOptions
{
    Width = 800,           // Viewport width (default: 1024)
    Height = 600,          // Viewport height (default: auto)
    Format = ImageFormat.Png,  // Jpg, Png, or WebP (default: Jpg)
    Quality = 90,          // 1-100, for Jpg/WebP (default: 100)
    FullPage = true,       // Capture full scrollable page (default: false)
    OmitBackground = true  // Transparent background for PNG/WebP (default: false)
};

var bytes = await converter.FromHtmlStringAsync(html, options);

Sync API (backward-compatible)

var converter = new HtmlConverter();
var bytes = converter.FromHtmlString(html);
var bytes = converter.FromUrl("https://example.com", width: 800, format: ImageFormat.Png, quality: 90);

Migrating from v1.x

v2.0 replaces wkhtmltoimage with headless Chromium. Key changes:

  • HtmlConverter now implements IAsyncDisposable/IDisposable — use await using or using for proper cleanup
  • New async methodsFromHtmlStringAsync and FromUrlAsync are the primary API
  • Sync methods still work with the same signatures as v1.x
  • New ImageFormat.WebP format option
  • macOS is now supported
  • No more embedded exe — Chromium is downloaded automatically on first use
  • Requires .NET 10.0+ (v1.x targeted .NET Standard 2.0)

MIT License

Copyright (c) 2020 Andrei M

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on CoreHtmlToImage:

Package Downloads
CHOCore.Tools

Package Description

Wey.Framework.NetCore

基于EF Core的Code First模式的DotNetCore快速开发框架

IcalToImage

Generate an image of a table from a calendar.

Wey.Framework.NetCore.6.0

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 203 4/1/2026
1.0.6 11,857,187 4/22/2020
1.0.5 163,647 12/3/2018
1.0.4 2,447 12/3/2018
1.0.3 2,611 12/3/2018
1.0.2 6,900 12/2/2018
1.0.1 2,841 12/2/2018
1.0.0 3,238 12/2/2018

v2.0.0: Replaced wkhtmltoimage with headless Chromium via PuppeteerSharp. Added async API, macOS support, WebP format, and options pattern.