---
title: "Set raster DPI for HTML-to-PDF shadows in C#"
url: https://recursiveai.org/onerender/cookbook/set-raster-dpi-for-html-pdf-effects/
description: "Set RasterDpi in C# to control how OneRender rasterizes CSS shadows and other effects in HTML-to-PDF output, without changing vector text."
version: "1.4.0"
---

# Set raster DPI for HTML-to-PDF shadows in C#

**OneRender** is a free, open-source HTML and CSS rendering library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneRender.Pdf) · [GitHub](https://github.com/recursive-ai-oss/onerender-csharp) · [Docs](https://recursiveai.org/onerender/docs/) · [Download example (.zip)](https://recursiveai.org/onerender/cookbook/set-raster-dpi-for-html-pdf-effects/set-raster-dpi-for-html-pdf-effects.zip)

Set `RasterDpi` for the shadow image; the default is 192 DPI. The heading stays selectable PDF text.

```shell
dotnet add package RecursiveAI.OneRender.Pdf
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneRender.Pdf;

const string html = "<h1 style='text-shadow:"
    + "2px 2px 2px #888'>Invoice</h1>";
using var file = File.Create("shadow.pdf");
var result = HtmlPdf.ToPdf(html, file, new()
{
    Output = new() { RasterDpi = 300 }
});
Console.WriteLine($"Pages: {result.PageCount}");
```

Writes `shadow.pdf` from the inline HTML and prints:

```text
Pages: 1
```

`RasterDpi` must be between 24 and 600; a value outside that range throws `ArgumentOutOfRangeException`.

Unzip [the example](https://recursiveai.org/onerender/cookbook/set-raster-dpi-for-html-pdf-effects/set-raster-dpi-for-html-pdf-effects.zip), then `dotnet run`.

## Variations

To request 96 DPI instead, replace the render call with this version. It writes the same one-page layout with fewer pixels in the embedded shadow image.

```csharp
var result = HtmlPdf.ToPdf(html, file, new()
{
    Output = new() { RasterDpi = 96 }
});
```

The program still prints `Pages: 1`.

## Related recipes

[Inspect HTML-to-PDF diagnostics](https://recursiveai.org/onerender/cookbook/inspect-html-to-pdf-diagnostics/) · [Render CSS box shadows to an image](https://recursiveai.org/onerender/cookbook/render-css-box-shadows-to-image/)

---

## The short answer

Set `PdfOutputOptions.RasterDpi` inside `HtmlPdfOptions.Output` before calling `HtmlPdf.ToPdf`. The example requests 300 dots per inch for the CSS text shadow behind “Invoice.” The heading itself remains PDF text.

## How do I set 300 DPI when converting HTML to PDF in C#?

Set `RasterDpi = 300` to make OneRender sample effects that need rasterization at that resolution. The engine calls these pieces *raster islands*: it draws the effect into an image and places the result back in its original position on the page. It doesn’t convert the page to a 300 DPI image or change the page’s physical dimensions. If you need a 300 DPI image of the whole page, that’s a separate rendering step.

For the example, the pixels belong to the shadow, not the text. Changing the DPI doesn’t change the font size or the layout, and you can still select or search for “Invoice.” PDF-native content such as text, paths and supported gradients doesn’t get resampled. The same option can affect other rasterized effects, such as inline SVG or filters other than opacity.

## Why doesn’t a blurred box shadow use the requested DPI?

A shadow without blur can be drawn as a PDF shape. For a blurred box shadow, OneRender can sample below the requested DPI because a wide blur has little fine detail. The box edge is still clipped by a vector shape. So increasing `RasterDpi` doesn’t necessarily add pixels to a wide, soft box shadow.

There’s also a pixel budget: at most 16 million pixels per island and 400 million per document. A large island may be drawn at reduced resolution, and an effect that exceeds the document budget can be skipped. Check `HtmlPdfResult.Diagnostics` when an effect looks different or is missing. The example’s text shadow is rasterized without a diagnostic on a successful write. See the [PDF output docs](https://recursiveai.org/onerender/docs/pdf/#vector-or-island) for which effects are rasterized and how the writer handles them.
