### Quick Start Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md A basic example demonstrating how to convert an HTML string to an image file. ```APIDOC ## Quick Start ```csharp await using var converter = new HtmlConverter(); // Convert HTML string to image var bytes = await converter.FromHtmlStringAsync("
Hello World!
"); File.WriteAllBytes("image.jpg", bytes); ``` ``` -------------------------------- ### Installation Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Instructions on how to install the CoreHtmlToImage NuGet package. ```APIDOC ## Installation ### NuGet Package Manager ``` Install-Package CoreHtmlToImage ``` ### dotnet CLI ``` dotnet add package CoreHtmlToImage ``` ``` -------------------------------- ### Quick Start: Convert HTML String to Image Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md A basic example demonstrating how to convert an HTML string to image bytes and save them to a file. Requires an instance of HtmlConverter. ```csharp await using var converter = new HtmlConverter(); // Convert HTML string to image var bytes = await converter.FromHtmlStringAsync("
Hello World!
"); File.WriteAllBytes("image.jpg", bytes); ``` -------------------------------- ### Install CoreHtmlToImage via NuGet Package Manager Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Use this command in the NuGet Package Manager Console to install the library. ```csharp Install-Package CoreHtmlToImage ``` -------------------------------- ### Install CoreHtmlToImage via CLI Source: https://context7.com/andrei-m-code/net-core-html-to-image/llms.txt Commands to add the library to your .NET project using NuGet or the dotnet CLI. ```bash # NuGet Package Manager Install-Package CoreHtmlToImage # dotnet CLI dotnet add package CoreHtmlToImage ``` -------------------------------- ### Convert URL to Image Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Example demonstrating how to convert a given URL into an image. ```APIDOC ## Convert URL to Image ```csharp await using var converter = new HtmlConverter(); var bytes = await converter.FromUrlAsync("https://example.com"); File.WriteAllBytes("screenshot.jpg", bytes); ``` ``` -------------------------------- ### Install CoreHtmlToImage via dotnet CLI Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Use this command in the .NET CLI to add the library to your project. ```bash dotnet add package CoreHtmlToImage ``` -------------------------------- ### Convert HTML String to Image Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Detailed example of converting a multi-line HTML string to an image. ```APIDOC ## Convert HTML String to Image ```csharp await using var converter = new HtmlConverter(); var html = @"

Hello World

This is rendered with headless Chromium.

"; var bytes = await converter.FromHtmlStringAsync(html); File.WriteAllBytes("output.jpg", bytes); ``` ``` -------------------------------- ### Specify ImageFormat for HTML to Image Conversion Source: https://context7.com/andrei-m-code/net-core-html-to-image/llms.txt Use the ImageFormat enum to select the desired output format: Jpg (default, good compression), Png (lossless, transparency), or WebP (modern, efficient compression). Magic bytes are provided as examples. ```csharp using CoreHtmlToImage; await using var converter = new HtmlConverter(); var html = "
Format Test
"; // JPEG format (default, best for photos, smaller size) var jpgOptions = new HtmlConverterOptions { Format = ImageFormat.Jpg, Quality = 90 }; var jpgBytes = await converter.FromHtmlStringAsync(html, jpgOptions); // Magic bytes: 0xFF 0xD8 (JPEG SOI marker) // PNG format (lossless, supports transparency) var pngOptions = new HtmlConverterOptions { Format = ImageFormat.Png }; var pngBytes = await converter.FromHtmlStringAsync(html, pngOptions); // Magic bytes: 0x89 0x50 0x4E 0x47 (PNG signature) // WebP format (modern, good compression with quality) var webpOptions = new HtmlConverterOptions { Format = ImageFormat.WebP, Quality = 85 }; var webpBytes = await converter.FromHtmlStringAsync(html, webpOptions); // Magic bytes: "RIFF" (0x52 0x49 0x46 0x46) Console.WriteLine($"JPG: {jpgBytes.Length} bytes"); Console.WriteLine($"PNG: {pngBytes.Length} bytes"); Console.WriteLine($"WebP: {webpBytes.Length} bytes"); ``` -------------------------------- ### Handling Conversion Errors with HtmlConversionException Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Provides an example of how to catch and handle HtmlConversionException, which is thrown for conversion failures. The inner exception contains the underlying PuppeteerSharp error. ```csharp try { var bytes = await converter.FromUrlAsync("https://invalid-url-example.test"); } catch (HtmlConversionException ex) { Console.WriteLine($"Conversion failed: {ex.Message}"); // ex.InnerException contains the underlying PuppeteerSharp exception } ``` -------------------------------- ### Using Options Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Demonstrates how to configure conversion options such as dimensions, format, and quality. ```APIDOC ## Using Options ```csharp await using var converter = new HtmlConverter(); var options = new HtmlConverterOptions { Width = 800, // Viewport width in pixels (default: 1024) Height = 600, // Viewport height in pixels (default: auto) Format = ImageFormat.Png, // Jpg, Png, or WebP (default: Jpg) Quality = 90, // 1-100, applies to Jpg only (default: 100) FullPage = true, // Capture full scrollable page (default: false) OmitBackground = true, // Transparent background for PNG/WebP (default: false) NavigationTimeout = 60000 // Navigation timeout in ms (default: 30000, 0 = no timeout) }; var bytes = await converter.FromHtmlStringAsync(html, options); ``` ``` -------------------------------- ### Configure Conversion Options Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Demonstrates how to use HtmlConverterOptions to customize image dimensions, format, quality, and other settings during conversion. ```csharp await using var converter = new HtmlConverter(); var options = new HtmlConverterOptions { Width = 800, // Viewport width in pixels (default: 1024) Height = 600, // Viewport height in pixels (default: auto) Format = ImageFormat.Png, // Jpg, Png, or WebP (default: Jpg) Quality = 90, // 1-100, applies to Jpg only (default: 100) FullPage = true, // Capture full scrollable page (default: false) OmitBackground = true, // Transparent background for PNG/WebP (default: false) NavigationTimeout = 60000 // Navigation timeout in ms (default: 30000, 0 = no timeout) }; var bytes = await converter.FromHtmlStringAsync(html, options); ``` -------------------------------- ### Perform HTML and URL Conversions Source: https://context7.com/andrei-m-code/net-core-html-to-image/llms.txt Demonstrates the full lifecycle of the HtmlConverter, including configuration options, asynchronous conversion, and resource disposal. ```csharp using CoreHtmlToImage; // Single converter instance for multiple conversions (recommended for performance) await using var converter = new HtmlConverter(); // Generate a report image var reportHtml = @"

Monthly Report - January 2024

$52,340
Revenue
1,247
Orders
94.2%
Satisfaction
"; var reportOptions = new HtmlConverterOptions { Width = 800, Format = ImageFormat.Png, Quality = 100 }; var reportBytes = await converter.FromHtmlStringAsync(reportHtml, reportOptions); File.WriteAllBytes("monthly-report.png", reportBytes); Console.WriteLine($"Report saved: {reportBytes.Length} bytes"); // Capture website screenshot var websiteOptions = new HtmlConverterOptions { Width = 1280, Height = 720, Format = ImageFormat.Jpg, Quality = 85, NavigationTimeout = 30000 }; using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1)); var websiteBytes = await converter.FromUrlAsync("https://example.com", websiteOptions, cts.Token); File.WriteAllBytes("website-screenshot.jpg", websiteBytes); Console.WriteLine($"Screenshot saved: {websiteBytes.Length} bytes"); // Converter is automatically disposed at end of scope // Browser process is cleaned up properly ``` -------------------------------- ### Convert HTML Strings with Options Source: https://context7.com/andrei-m-code/net-core-html-to-image/llms.txt Demonstrates converting HTML strings to images, including the use of HtmlConverterOptions for custom dimensions and formats. ```csharp using CoreHtmlToImage; await using var converter = new HtmlConverter(); // Basic HTML conversion var simpleHtml = "
Hello World!
"; var bytes = await converter.FromHtmlStringAsync(simpleHtml); File.WriteAllBytes("simple.jpg", bytes); // Full HTML document with styles var styledHtml = @"

Report Generated

Date: 2024-01-15

"; var options = new HtmlConverterOptions { Width = 800, Format = ImageFormat.Png, OmitBackground = false }; var styledBytes = await converter.FromHtmlStringAsync(styledHtml, options); File.WriteAllBytes("styled-report.png", styledBytes); // Result: 800px wide PNG image with styled content ``` -------------------------------- ### Cancellation Support with CancellationToken Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Shows how to integrate CancellationToken to cancel asynchronous conversion operations, useful for time-limited requests. ```csharp using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); var bytes = await converter.FromUrlAsync("https://example.com", options, cts.Token); ``` -------------------------------- ### Synchronous HTML to Image Conversion (v1.x) Source: https://context7.com/andrei-m-code/net-core-html-to-image/llms.txt Use synchronous methods like FromHtmlString and FromUrl for migrating from v1.x or when async is not feasible. Note that these methods block the calling thread. ```csharp using CoreHtmlToImage; // Sync disposal using var converter = new HtmlConverter(); // FromHtmlString - synchronous HTML conversion var htmlBytes = converter.FromHtmlString( "

Hello World

", width: 800, format: ImageFormat.Png, quality: 100 ); File.WriteAllBytes("sync-html.png", htmlBytes); // FromUrl - synchronous URL capture var urlBytes = converter.FromUrl( "https://example.com", width: 1024, format: ImageFormat.Jpg, quality: 85 ); File.WriteAllBytes("sync-url.jpg", urlBytes); // Note: Sync methods block the calling thread. // Prefer async API for new code. ``` -------------------------------- ### Disposing HtmlConverter Instance (Async) Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Demonstrates the preferred asynchronous disposal pattern for the HtmlConverter to release resources, including the headless Chromium process. ```csharp await using var converter = new HtmlConverter(); ``` -------------------------------- ### Options Reference Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md A detailed reference for all available `HtmlConverterOptions` properties. ```APIDOC ## Options Reference | Property | Type | Default | Description | |---|---|---|---| | `Width` | `int` | `1024` | Viewport width in pixels | | `Height` | `int?` | `null` (auto) | Viewport height in pixels. When null, height is determined automatically | | `Format` | `ImageFormat` | `Jpg` | Output format: `Jpg`, `Png`, or `WebP` | | `Quality` | `int` | `100` | Image quality from 1 to 100. Applies to Jpg only | | `FullPage` | `bool` | `false` | When true, captures the full scrollable page instead of just the viewport | | `OmitBackground` | `bool` | `false` | When true, hides the default white background for transparent PNG/WebP output | | `NavigationTimeout` | `int` | `30000` | Maximum time in milliseconds to wait for page navigation. Set to 0 for no timeout | ``` -------------------------------- ### FromUrlAsync Method Source: https://context7.com/andrei-m-code/net-core-html-to-image/llms.txt Asynchronously captures a screenshot of a web page from a URL with various configuration options. ```APIDOC ## FromUrlAsync Method Asynchronously captures a screenshot of a web page from a URL. Waits for network idle before capturing to ensure all resources are loaded. ### Method ```csharp // Basic URL screenshot var bytes = await converter.FromUrlAsync("https://example.com"); File.WriteAllBytes("example.jpg", bytes); // Full-page screenshot with custom options var options = new HtmlConverterOptions { Width = 1280, Height = 800, Format = ImageFormat.Png, FullPage = true, NavigationTimeout = 60000 // 60 second timeout for slow pages }; var fullPageBytes = await converter.FromUrlAsync("https://github.com", options); File.WriteAllBytes("github-fullpage.png", fullPageBytes); // With cancellation support using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); try { var bytes2 = await converter.FromUrlAsync("https://example.com", options, cts.Token); File.WriteAllBytes("with-cancellation.png", bytes2); } catch (OperationCanceledException) { Console.WriteLine("Screenshot capture was cancelled"); } ``` ### Parameters #### Path Parameters - **url** (string) - Required - The URL of the web page to capture. #### Query Parameters - **options** (HtmlConverterOptions) - Optional - Configuration options for the screenshot. - **cancellationToken** (CancellationToken) - Optional - Token to cancel the operation. ``` -------------------------------- ### Synchronous API Usage (v1.x compatible) Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Illustrates the use of the synchronous API for HTML to image conversion, which is compatible with older versions but blocks the calling thread. ```csharp var converter = new HtmlConverter(); // Same signatures as v1.x var bytes = converter.FromHtmlString("

Hello

"); var bytes = converter.FromUrl("https://example.com", width: 800, format: ImageFormat.Png, quality: 90); ``` -------------------------------- ### Cancellation Support Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Shows how to use `CancellationToken` to cancel asynchronous conversion operations. ```APIDOC ## Cancellation Support Async methods accept a `CancellationToken`: ```csharp using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); var bytes = await converter.FromUrlAsync("https://example.com", options, cts.Token); ``` ``` -------------------------------- ### Sync API Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Details on the synchronous API, which is backward-compatible with v1.x, and a note on its performance implications. ```APIDOC ## Sync API (backward-compatible with v1.x) The synchronous API from v1.x is still available with the same method signatures: ```csharp var converter = new HtmlConverter(); // Same signatures as v1.x var bytes = converter.FromHtmlString("

Hello

"); var bytes = converter.FromUrl("https://example.com", width: 800, format: ImageFormat.Png, quality: 90); ``` > **Note:** The async API is recommended for new code. The sync methods block the calling thread while waiting for Chromium. ``` -------------------------------- ### Disposing HtmlConverter Instance (Sync) Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Shows the synchronous disposal pattern for the HtmlConverter. It's recommended to use the async pattern for new code. ```csharp using var converter = new HtmlConverter(); ``` -------------------------------- ### Synchronous Conversion Methods Source: https://context7.com/andrei-m-code/net-core-html-to-image/llms.txt Legacy synchronous methods for converting HTML or URLs to images, provided for v1.x compatibility. ```APIDOC ## POST /HtmlConverter/FromHtmlString ## POST /HtmlConverter/FromUrl ### Description Synchronous versions of the conversion methods. Note that these block the calling thread. ### Parameters #### Request Body - **html/url** (string) - Required - The source content. - **width** (int) - Optional - Viewport width. - **format** (ImageFormat) - Optional - Output format (Jpg, Png, WebP). - **quality** (int) - Optional - Image quality (1-100). ``` -------------------------------- ### Disposal Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Guidance on properly disposing the `HtmlConverter` instance to release resources, including the headless Chromium process. ```APIDOC ## Disposal `HtmlConverter` manages a headless Chromium browser process internally. Always dispose it when done: ```csharp // Async (preferred) await using var converter = new HtmlConverter(); // Sync using var converter = new HtmlConverter(); ``` The browser instance is reused across multiple conversions for performance. A single `HtmlConverter` instance is safe to use from multiple threads concurrently. ``` -------------------------------- ### Capture URL Screenshots with Advanced Options Source: https://context7.com/andrei-m-code/net-core-html-to-image/llms.txt Captures screenshots from URLs using custom options like full-page rendering, timeouts, and cancellation tokens. ```csharp using CoreHtmlToImage; await using var converter = new HtmlConverter(); // Basic URL screenshot var bytes = await converter.FromUrlAsync("https://example.com"); File.WriteAllBytes("example.jpg", bytes); // Full-page screenshot with custom options var options = new HtmlConverterOptions { Width = 1280, Height = 800, Format = ImageFormat.Png, FullPage = true, NavigationTimeout = 60000 // 60 second timeout for slow pages }; var fullPageBytes = await converter.FromUrlAsync("https://github.com", options); File.WriteAllBytes("github-fullpage.png", fullPageBytes); // With cancellation support using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); try { var bytes2 = await converter.FromUrlAsync("https://example.com", options, cts.Token); File.WriteAllBytes("with-cancellation.png", bytes2); } catch (OperationCanceledException) { Console.WriteLine("Screenshot capture was cancelled"); } ``` -------------------------------- ### Configure HtmlConverterOptions for Image Output Source: https://context7.com/andrei-m-code/net-core-html-to-image/llms.txt Customize image generation with HtmlConverterOptions. Set viewport dimensions, output format (PNG, WebP, JPG), transparency, quality, and capture behavior like full-page or navigation timeouts. ```csharp using CoreHtmlToImage; await using var converter = new HtmlConverter(); var html = "
Tall content
"; // High-quality PNG with custom viewport var pngOptions = new HtmlConverterOptions { Width = 1024, // Viewport width in pixels (default: 1024) Height = 768, // Viewport height in pixels (default: auto) Format = ImageFormat.Png, OmitBackground = true // Transparent background for PNG/WebP }; var pngBytes = await converter.FromHtmlStringAsync(html, pngOptions); File.WriteAllBytes("transparent.png", pngBytes); // Result: PNG with transparency where HTML has no background // Full-page capture with WebP format var fullPageOptions = new HtmlConverterOptions { Width = 800, Format = ImageFormat.WebP, Quality = 85, // 1-100, applies to JPG and WebP (default: 100) FullPage = true, // Capture entire scrollable page NavigationTimeout = 60000 // 60 seconds (default: 30000ms) }; var webpBytes = await converter.FromHtmlStringAsync(html, fullPageOptions); File.WriteAllBytes("fullpage.webp", webpBytes); // Compressed JPEG for smaller file size var jpgOptions = new HtmlConverterOptions { Width = 640, Format = ImageFormat.Jpg, Quality = 75 // Lower quality = smaller file size }; var jpgBytes = await converter.FromHtmlStringAsync(html, jpgOptions); File.WriteAllBytes("compressed.jpg", jpgBytes); ``` -------------------------------- ### HtmlConverter.FromUrlAsync Source: https://context7.com/andrei-m-code/net-core-html-to-image/llms.txt Captures a webpage from a URL and converts it into an image byte array asynchronously. ```APIDOC ## POST /HtmlConverter/FromUrlAsync ### Description Navigates to a URL and captures the rendered content as an image. ### Parameters #### Request Body - **url** (string) - Required - The URL to capture. - **options** (HtmlConverterOptions) - Optional - Configuration object for the capture process. ### Response #### Success Response (200) - **bytes** (byte[]) - The resulting image data. ``` -------------------------------- ### FromHtmlStringAsync Method Source: https://context7.com/andrei-m-code/net-core-html-to-image/llms.txt Asynchronously converts an HTML string to image bytes with optional configuration. ```APIDOC ## FromHtmlStringAsync Method Asynchronously converts an HTML string to image bytes. This is the recommended method for converting HTML content to images in modern async .NET applications. ### Method ```csharp // Basic HTML conversion var simpleHtml = "
Hello World!
"; var bytes = await converter.FromHtmlStringAsync(simpleHtml); File.WriteAllBytes("simple.jpg", bytes); // Full HTML document with styles and options var styledHtml = @"

Report Generated

Date: 2024-01-15

"; var options = new HtmlConverterOptions { Width = 800, Format = ImageFormat.Png, OmitBackground = false }; var styledBytes = await converter.FromHtmlStringAsync(styledHtml, options); File.WriteAllBytes("styled-report.png", styledBytes); ``` ### Parameters #### Request Body - **html** (string) - Required - The HTML content to convert. - **options** (HtmlConverterOptions) - Optional - Configuration options for the conversion. ``` -------------------------------- ### Error Handling Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Information on how to handle conversion errors, which are thrown as `HtmlConversionException`. ```APIDOC ## Error Handling Conversion errors throw `HtmlConversionException`: ```csharp try { var bytes = await converter.FromUrlAsync("https://invalid-url-example.test"); } catch (HtmlConversionException ex) { Console.WriteLine($"Conversion failed: {ex.Message}"); // ex.InnerException contains the underlying PuppeteerSharp exception } ``` ``` -------------------------------- ### Convert HTML and URLs with HtmlConverter Source: https://context7.com/andrei-m-code/net-core-html-to-image/llms.txt Basic usage of the HtmlConverter class to generate images from HTML strings and external URLs. ```csharp using CoreHtmlToImage; // Create converter instance (downloads Chromium on first use if needed) await using var converter = new HtmlConverter(); // Convert HTML string to JPG (default format) var html = @"

Hello World

This is rendered with headless Chromium.

"; var jpgBytes = await converter.FromHtmlStringAsync(html); File.WriteAllBytes("output.jpg", jpgBytes); // Result: JPEG image bytes (magic bytes: 0xFF 0xD8) // Convert a URL to image var urlBytes = await converter.FromUrlAsync("https://example.com"); File.WriteAllBytes("screenshot.jpg", urlBytes); ``` -------------------------------- ### Convert URL to Image Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Converts the content of a given URL to image bytes. The HtmlConverter instance should be disposed after the operation. ```csharp await using var converter = new HtmlConverter(); var bytes = await converter.FromUrlAsync("https://example.com"); File.WriteAllBytes("screenshot.jpg", bytes); ``` -------------------------------- ### CoreHtmlToImage Usage Source: https://context7.com/andrei-m-code/net-core-html-to-image/llms.txt Basic usage of the HtmlConverter class to convert HTML strings and URLs to image bytes. ```APIDOC ## CoreHtmlToImage Usage This section demonstrates the basic instantiation and usage of the `HtmlConverter` class. ### Method ```csharp // Create converter instance (downloads Chromium on first use if needed) await using var converter = new HtmlConverter(); // Convert HTML string to JPG (default format) var html = @"

Hello World

This is rendered with headless Chromium.

"; var jpgBytes = await converter.FromHtmlStringAsync(html); File.WriteAllBytes("output.jpg", jpgBytes); // Convert a URL to image var urlBytes = await converter.FromUrlAsync("https://example.com"); File.WriteAllBytes("screenshot.jpg", urlBytes); ``` ``` -------------------------------- ### Convert HTML String to Image Source: https://github.com/andrei-m-code/net-core-html-to-image/blob/master/README.md Converts a given HTML string to image bytes. Ensure the HtmlConverter is properly disposed after use. ```csharp await using var converter = new HtmlConverter(); var html = @"

Hello World

This is rendered with headless Chromium.

"; var bytes = await converter.FromHtmlStringAsync(html); File.WriteAllBytes("output.jpg", bytes); ``` -------------------------------- ### HtmlConverter.FromHtmlStringAsync Source: https://context7.com/andrei-m-code/net-core-html-to-image/llms.txt Converts an HTML string into an image byte array asynchronously using specified conversion options. ```APIDOC ## POST /HtmlConverter/FromHtmlStringAsync ### Description Converts a provided HTML string into an image format based on the provided HtmlConverterOptions. ### Parameters #### Request Body - **html** (string) - Required - The HTML content to convert. - **options** (HtmlConverterOptions) - Optional - Configuration object containing Width, Height, Format, Quality, OmitBackground, FullPage, and NavigationTimeout. ### Response #### Success Response (200) - **bytes** (byte[]) - The resulting image data. ``` -------------------------------- ### Handle HtmlConversionException During Conversion Source: https://context7.com/andrei-m-code/net-core-html-to-image/llms.txt Catch HtmlConversionException for conversion failures, accessing the InnerException for underlying PuppeteerSharp errors. Also handles ArgumentException for invalid inputs and ObjectDisposedException if the converter is used after disposal. ```csharp using CoreHtmlToImage; await using var converter = new HtmlConverter(); // Handle conversion errors try { var bytes = await converter.FromUrlAsync("https://this-domain-does-not-exist.invalid"); } catch (HtmlConversionException ex) { Console.WriteLine($"Conversion failed: {ex.Message}"); // Output: "Conversion failed: Failed to convert URL 'https://...' to image: ..." if (ex.InnerException != null) { Console.WriteLine($"Underlying error: {ex.InnerException.Message}"); // Contains PuppeteerSharp exception details } } // Handle argument validation errors try { var bytes = await converter.FromHtmlStringAsync(""); } catch (ArgumentException ex) { Console.WriteLine($"Invalid argument: {ex.Message}"); // Output: "Invalid argument: html (Parameter 'html')" } // Handle disposed converter var disposedConverter = new HtmlConverter(); await disposedConverter.DisposeAsync(); try { var bytes = await disposedConverter.FromHtmlStringAsync("

Test

"); } catch (ObjectDisposedException ex) { Console.WriteLine("Converter has been disposed"); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.