CoreHtmlToImage 2.0.0
dotnet add package CoreHtmlToImage --version 2.0.0
NuGet\Install-Package CoreHtmlToImage -Version 2.0.0
<PackageReference Include="CoreHtmlToImage" Version="2.0.0" />
<PackageVersion Include="CoreHtmlToImage" Version="2.0.0" />
<PackageReference Include="CoreHtmlToImage" />
paket add CoreHtmlToImage --version 2.0.0
#r "nuget: CoreHtmlToImage, 2.0.0"
#:package CoreHtmlToImage@2.0.0
#addin nuget:?package=CoreHtmlToImage&version=2.0.0
#tool nuget:?package=CoreHtmlToImage&version=2.0.0
.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
Async API (recommended)
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:
HtmlConverternow implementsIAsyncDisposable/IDisposable— useawait usingorusingfor proper cleanup- New async methods —
FromHtmlStringAsyncandFromUrlAsyncare the primary API - Sync methods still work with the same signatures as v1.x
- New
ImageFormat.WebPformat 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 | Versions 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. |
-
net10.0
- PuppeteerSharp (>= 21.1.1)
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.
v2.0.0: Replaced wkhtmltoimage with headless Chromium via PuppeteerSharp. Added async API, macOS support, WebP format, and options pattern.