October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
ASP.NET

How to Convert HTML to JPEG in C#

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To convert HTML to JPEG in C#, render the page in a browser engine such as Chromium, then save the rendered pixels as a JPEG. For a short library-level implementation, use CoreHtmlToImage; for more control, use PuppeteerSharp or Playwright for .NET. SkiaSharp can encode pixels you already have, but it does not render HTML or CSS.

Choose a rendering approach

A browser is usually the right tool because it performs the layout, CSS styling, and JavaScript execution that turn HTML into pixels. The best choice depends on whether you want a compact API, direct control of a browser, or a managed service.

Approach Best fit What to account for
CoreHtmlToImage 2.0.0 Converting an HTML string or URL with a short .NET API Uses headless Chromium through PuppeteerSharp; first use downloads a compatible browser binary.
PuppeteerSharp Direct control over Chromium navigation, viewport, and screenshot options You manage browser installation, processes, waits, and deployment requirements.
Playwright for .NET Projects already using Playwright automation or testing Browser installation and process management remain part of the application setup.
Hosted API Teams that prefer not to operate browser processes and binaries Review the service’s current authentication, data handling, pricing, and limits.
SkiaSharp Encoding an existing raster image as JPEG It is an image encoder, not an HTML renderer.

The examples below focus on local .NET rendering. If you already have pixels, use SkiaSharp for the encoding step rather than expecting it to interpret HTML.

Convert HTML with CoreHtmlToImage

CoreHtmlToImage provides the shortest high-level route from an HTML string or URL to image bytes. Version 2.0.0 uses headless Chromium and documents JPEG, PNG, and WebP output, along with viewport size, quality, full-page capture, and background controls.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install the NuGet package:

dotnet add package CoreHtmlToImage --version 2.0.0

Then render a string and save the returned bytes:

using CoreHtmlToImage;

var html = """
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <style>
    body { font: 16px sans-serif; margin: 0; padding: 32px; background: #fff; }
    h1 { color: #174ea6; }
  </style>
</head>
<body>
  <h1>Hello from HTML</h1>
  <p>Rendered to a JPEG by Chromium.</p>
</body>
</html>
""";

await using var converter = new HtmlConverter();
var options = new HtmlConverterOptions
{
    Width = 1200,
    Height = 630,
    Format = ImageFormat.Jpg,
    Quality = 90,
    FullPage = true
};

var bytes = await converter.FromHtmlStringAsync(html, options);
await File.WriteAllBytesAsync("output.jpg", bytes);

For a public page, use the URL conversion method documented by the package instead of constructing an HTML string. Configure the same output options, then write the returned bytes to disk or return them from your application. The package documents both string and URL methods.

CoreHtmlToImage 2.0 replaced its earlier wkhtmltoimage-based rendering with Chromium, added async APIs, macOS support, and WebP output. Its package metadata says PuppeteerSharp downloads a compatible Chromium binary on first use—about 200 MB—and caches it for later runs. Include that download and browser storage in deployment planning.

Use PuppeteerSharp for direct browser control

PuppeteerSharp is a .NET port of Puppeteer. Choose it when you need to control browser navigation and screenshot behavior directly, or when you want to add waits and page setup around the capture.

Install the package:

dotnet add package PuppeteerSharp

Basic URL-to-JPEG example:

using PuppeteerSharp;

await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
    Headless = true
});

await using var page = await browser.NewPageAsync();
await page.SetViewportAsync(new ViewPortOptions
{
    Width = 1200,
    Height = 630
});

await page.GoToAsync("https://example.com");
await page.ScreenshotAsync("output.jpg", new ScreenshotOptions
{
    Type = ScreenshotType.Jpeg,
    Quality = 90,
    FullPage = true
});

The screenshot API accepts JPEG, PNG, and WebP. For JPEG and WebP, quality is an integer from 0 to 100. FullPage = true captures the full scrollable page; otherwise the screenshot is limited to the viewport. The screenshot API can also infer the image type from the output file extension, but setting the type explicitly makes the intended format clear.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For markup held in a string, navigate to a safely encoded data:text/html URL or serve the content from a local endpoint. Do not concatenate arbitrary HTML directly into a data URL: characters such as spaces, percent signs, and non-ASCII text need correct URL encoding. For application pages, a local endpoint is often simpler, especially when the HTML depends on relative assets or scripts.

Use Playwright for .NET

Playwright is a natural fit if the application already uses its browser automation or testing APIs. Its page screenshot options support JPEG type, quality, full-page capture, clipping, and a path for the output.

await page.ScreenshotAsync(new PageScreenshotOptions
{
    Path = "output.jpg",
    Type = ScreenshotType.Jpeg,
    Quality = 90,
    FullPage = true
});

When you need only a rectangular region, set the screenshot clip options rather than capturing the whole page and cropping afterward. If you need an element rather than coordinates, use the appropriate locator or element screenshot API in the Playwright version installed by your project.

Choose the capture size and JPEG settings

Viewport or full page

  • Fixed viewport: Set width and height explicitly for thumbnails, social cards, or any output that must have predictable dimensions. Responsive CSS will lay out the page at that viewport.
  • Full-page capture: Set FullPage = true when the output should include the entire scrollable document. Very long pages can produce large images and higher memory use.
  • Clipped region or component: Capture a defined rectangle or a specific element when the reader needs one chart, card, or section rather than the whole page.

Quality and background

Set JPEG quality explicitly so a package default does not silently determine the trade-off. A value around 80–90 is a reasonable starting point, not a universal optimum: inspect small text, gradients, and file size using the actual page. JPEG is lossy and has no alpha transparency. If transparency matters, choose PNG instead; a transparent-background option does not make JPEG transparent.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Wait for the page you intend to capture

Navigation completion does not guarantee that every image, font, or client-rendered component is ready. Wait for a known selector, application-ready signal, or required assets before taking the screenshot. A fixed delay can help with a known slow element, but it is less reliable than waiting for a specific condition. Pages that depend on external fonts or images may render differently when those requests fail or arrive late.

Where other tools fit

Legacy wkhtmltoimage

wkhtmltoimage is an open-source LGPLv3 command-line tool from the wkhtmltopdf project. It renders with Qt WebKit in headless mode. It may remain useful in an established deployment, but check its CSS and JavaScript behavior against the pages you need. CoreHtmlToImage’s move in version 2 to Chromium reflects why a current browser engine is a safer default for modern pages.

SkiaSharp

SkiaSharp’s SKPixmap API provides JPEG, PNG, and WebP encoding methods, including stream and quality-oriented overloads. Use it after another component has rendered HTML into pixels. It does not calculate browser layout, load CSS, or execute JavaScript.

Hosted rendering

HtmlCssToImage (HCTI) documents a C#/.NET package and a hosted API request with format: jpeg, viewport width and height, and a returned hosted .jpeg URL. Its documentation says managed Chromium handles page rendering, avoiding the need to maintain local browser processes and binaries. Check the provider’s current terms for authentication, data handling, pricing, and rate limits before sending page content to a hosted service.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. A single GET request can return a screenshot as PNG, JPEG, or WebP, or return a PDF. It can accept consent banners as a visitor and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, with page verdict and billing information in response headers.

For a JPEG, request the format=jpeg output option and save the response bytes:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -d format=jpeg -o shot.jpg

See the ScreenshotNeo API documentation for authentication and supported parameters. ScreenshotNeo also has an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. Every plan includes its features; the Free plan includes 1,000 shots per month without a card, and paid plans start at $5 for 3,000 shots. Sign up for the free plan to try it with no card.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting

The output is blank or only partly rendered

  • Cause: The page needs client-side JavaScript, fonts, images, or an API response that has not completed when capture begins.
  • Fix: Wait for the application-specific ready selector or state, and verify the page has loaded its required assets before taking the screenshot. Check the rendered page in a normal browser at the same viewport.

Chromium will not launch in deployment

  • Cause: The browser binary is missing, the first-run download could not complete, or the deployment environment lacks required runtime support or writable cache storage.
  • Fix: Install or download the compatible browser during image/build setup, ensure the runtime can access the cached binary, and test launch in the same container or host configuration used in production. Account for CoreHtmlToImage’s first-use Chromium download and cache.

The image is clipped or has the wrong dimensions

  • Cause: The configured viewport is not the intended responsive layout, or the page extends beyond the viewport while full-page capture is off.
  • Fix: Set explicit viewport width and height. Enable full-page capture for the full document, or use a clip/element screenshot for a specific area.

The JPEG has a solid background

  • Cause: JPEG does not support an alpha channel.
  • Fix: Use a deliberate solid page background for JPEG, or switch to PNG when transparency is required.

Text or gradients look noisy

  • Cause: JPEG compression is lossy, and a low quality setting can introduce artifacts around sharp edges.
  • Fix: Increase quality and compare file size, or use PNG for graphics with crisp text and flat colors.

Relative images or styles are missing from an HTML string

  • Cause: A data URL has no ordinary site base path for relative resource references.
  • Fix: Use absolute resource URLs or serve the HTML from a local endpoint with the expected base path. Confirm that external resources are reachable from the machine running Chromium.

Performance, reliability, and cost

Local browser rendering avoids sending page contents to a hosted renderer, but your application must provision browser binaries, launch processes, and manage concurrency. Reuse browser processes where the chosen library and application architecture allow it, while keeping page instances isolated as needed. Full-page images and high-resolution viewports use more memory than small viewport captures. No comparative performance benchmark is established here, so test representative pages and expected concurrency in your own deployment rather than relying on a generic speed claim.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Browser-based rendering is more faithful to modern CSS and JavaScript than a legacy renderer, but it does not make a page deterministic by itself. Network dependencies, animation, time-sensitive content, and client-side data can change the captured pixels. For stable output, control the viewport, wait conditions, page inputs, and any time-dependent content. A hosted renderer shifts browser maintenance to a service boundary, but introduces vendor terms and data-handling considerations.

Frequently Asked Questions

Can I convert an HTML string directly to JPEG in C#?

Yes. CoreHtmlToImage documents an HTML-string method, and PuppeteerSharp can load safely encoded markup or markup served locally before taking a JPEG screenshot.

Does changing the file extension to .jpg convert HTML?

No. HTML must first be laid out and rendered by a browser engine; only then can the resulting pixels be encoded as JPEG.

Does SkiaSharp render HTML or CSS?

No. SkiaSharp can encode raster pixels as JPEG, PNG, or WebP, but an HTML renderer must create those pixels first.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.