HtmlCssToImage 0.0.9

dotnet add package HtmlCssToImage --version 0.0.9
                    
NuGet\Install-Package HtmlCssToImage -Version 0.0.9
                    
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="HtmlCssToImage" Version="0.0.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HtmlCssToImage" Version="0.0.9" />
                    
Directory.Packages.props
<PackageReference Include="HtmlCssToImage" />
                    
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 HtmlCssToImage --version 0.0.9
                    
#r "nuget: HtmlCssToImage, 0.0.9"
                    
#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 HtmlCssToImage@0.0.9
                    
#: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=HtmlCssToImage&version=0.0.9
                    
Install as a Cake Addin
#tool nuget:?package=HtmlCssToImage&version=0.0.9
                    
Install as a Cake Tool

HTML/CSS to Image

.NET / C# Client

HCTI Logo

This package provides a .NET client for the HTML/CSS to Image API, allowing you to generate images from HTML/CSS content directly from your .NET applications.

NuGet Version

Getting Started

Installation

Add the package to your project:

dotnet add package HtmlCssToImage

Configuration

Creating a new instance of the HtmlCssToImageClient:

var options = new HtmlCssToImageClientOptions("api-id", "api-key");
var http = new HttpClient();
var client = new HtmlCssToImageClient(http, options);

If you're using ASP.NET Core or similar frameworks supporting Microsoft DI, check out the HtmlCssToImage.DependencyInjection Package Docs for how to inject the client into your application.

Creating Images

You can generate images using your HCTI client with strongly typed parameters:

Type Description
CreateHtmlCssImageRequest The request object for creating an image from HTML & CSS content
CreateUrlImageRequest The request object for creating an image from a URL
CreateTemplatedImageRequest The request object for creating an image from a template

Here's a basic example of creating an image from HTML & CSS content:


var html_request = new CreateHtmlCssImageRequest()
{
    Html = "<h1>Hello World</h1>",
    Css = "h1 { color: red; }",
    ViewportWidth = 200,
    ViewportHeight = 400
};

var html_image = await client.CreateImageAsync(html_request);

if(html_image.Success)
{
    Console.WriteLine(html_image.Response.Url);
}else{
    Console.WriteLine(html_image.ErrorDetails.Message);
}

Image creation responds with an ApiResult<CreateImageResponse>. ApiResult<T> is a simple wrapper around Api responses that provides an indicator of Success and potentially ErrorDetails if the request failed.

Template Helpers

When creating a templated image, you can use static helper methods FromObject<T> on the CreateTemplatedImageRequest class to generate a template, providing serialization options for AOT/serialization control. See more below in the Performance & Native AOT section.

// Create a template from an object, using default serialization options. This will warn in AOT scenarios
public static CreateTemplatedImageRequest CreateTemplatedImageRequest.FromObject<T>(T templateValuies, string templateId, long? templateVersion = null)
    
// Create a template from an object, providing JsonSerializationOptions for serialization control
public static CreateTemplatedImageRequest FromObject<T>(T templateValues, string templateId, JsonSerializerOptions jsonSerializerOptions, long? templateVersion = null) 

// Create a template from an object, providing JsonTypeInfo<T>
public static CreateTemplatedImageRequest FromObject<T>(T templateValues, string templateId, JsonTypeInfo<T> typeInfo, long? templateVersion = null) 

Creating an Image Batch

Call CreateImageBatchAsync<T> on the client to create a batch of images from a collection of either CreateHtmlCssImageRequest or CreateUrlImageRequest objects. At this time, templates are not supported in batch requests.

You can construct a CreateImageBatchRequest object directly or use the overload on HtmlCssToImageClient that accepts defaultOptions and variations as parameters.

Batch creation responds with an ApiResult<CreateImageResponse[]>. ApiResult<T> is a simple wrapper around Api responses that provides an indicator of Success and potentially ErrorDetails if the request failed.

If your request is successful, the Response property will be an array in the order of your variations.

Creating Image URLs

You can generate signed URLs for images without actually calling the API by calling CreateAndRenderUrl or one of the CreateTemplatedImageUrl methods.

These methods are synchronous because they don't make any network calls or do heavy IO, and have been designed to be very high performance.

Read more about signed URLs in the create-and-render docs.

These URLs are tied to the API Key & API Id you provide when creating the client. If you change them or disable the keys, you'll need to generate new URLs.

These methods are handy when you have a lot of content that may never be rendered, and want to render on-demand, as to not waste your image credits.

Performance & Native AOT

This library is built with performance in mind and is fully compatible with Native AOT (Ahead-of-Time) compilation in .NET 9+.

The client internally uses source-generated JSON serialization, so no extra configuration is required for standard API requests.

AOT with Templated Images

When using templates, you provide a custom object for templateValues. In a Native AOT environment, reflection is restricted, so you must ensure your types are source-generated. Ensure you use the overloads with JsonTypeInfo<T> or JsonSerializerOptions to provide serialization options. If you're providing JsonSerializerOptions, ensure it has the type info in its resolver chain. Check out the Microsoft JSON docs for more details.

Other Packages

HtmlCssToImage.DependencyInjection

Use HtmlCssToImage.DependencyInjection to integrate the HtmlCssToImage client into your ASP.NET Core application.

HtmlCssToImage.Blazor

Use HtmlCssToImage.Blazor to generate Open Graph image tags using HCTI links in your Blazor applications.

HtmlCssToImage.TagHelpers

Use HtmlCssToImage.TagHelpers to generate Open Graph image tags in ASP.NET Core Razor Pages and MVC applications.


Check out the HTML/CSS To Image Docs for more details on the API's capabilities.

Get started for free at htmlcsstoimage.com.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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.
  • net10.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on HtmlCssToImage:

Package Downloads
HtmlCssToImage.DependencyInjection

DI Support for the HTML/CSS to Image API client.

HtmlCssToImage.Blazor

Official Blazor integration for HTML/CSS to Image API. Add automated OG meta tags to your pages.

HtmlCssToImage.TagHelpers

Official Tag Helpers for HTML/CSS to Image API. Add automated OG meta tags to your pages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.9 53 1/9/2026
0.0.8 58 1/7/2026
0.0.7 56 1/6/2026
0.0.6 53 1/6/2026
0.0.5 52 1/6/2026
0.0.4 52 1/6/2026