---
title: "Inspect HTML-to-PDF diagnostics in C#"
url: https://recursiveai.org/onerender/cookbook/inspect-html-to-pdf-diagnostics/
description: "Find missing glyphs when converting HTML to PDF in C#. Read OneRender’s page count and rendering diagnostics instead of accepting missing characters."
version: "1.4.0"
---

# Inspect HTML-to-PDF diagnostics 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/inspect-html-to-pdf-diagnostics/inspect-html-to-pdf-diagnostics.zip)

Catch missing characters even when PDF conversion succeeds.

```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;

using var output =
    File.Create("diagnostics.pdf");
var result = HtmlPdf.ToPdf(
    "<p>Hello &#x10FFFF;</p>", output);
Console.WriteLine($"Pages: {result.PageCount}");
foreach (var item in result.Diagnostics)
    Console.WriteLine(
        $"{item.Kind}: {item.Message}");
```

```text
Pages: 1
MissingGlyph: No font has a glyph for U+10FFFF. No optional fonts package covers it.
```

All HTML and CSS are embedded in `Program.cs`; no input files are needed.

The sample deliberately requests U+10FFFF, which no optional font package covers. The PDF is still written; a missing glyph is a diagnostic, not an exception. Conversion failures such as exceeding `MaxPages` throw `PdfRenderException`.

Unzip [the example](https://recursiveai.org/onerender/cookbook/inspect-html-to-pdf-diagnostics/inspect-html-to-pdf-diagnostics.zip), then `dotnet run`.

## Variations

After the loop, classify the diagnostics instead of parsing their message strings:

```csharp
Console.WriteLine($"Has missing glyphs: {result.Diagnostics.Any(
    d => d.Kind == OneRender.DiagnosticKind.MissingGlyph)}");
```

```text
Has missing glyphs: True
```

## Related recipes

- [Convert HTML to PDF](https://recursiveai.org/onerender/cookbook/html-to-pdf/)
- [Choose fonts for rendered HTML](https://recursiveai.org/onerender/cookbook/fonts/)

## The short answer

Use the stream overload of `HtmlPdf.ToPdf`. It returns `HtmlPdfResult`, which contains `PageCount` and `Diagnostics`. Enumerate each diagnostic’s `Kind` and `Message` after the call. The byte-array overload is convenient for saving a file, but it does not return this result object.

The complete program intentionally includes a character no available font can draw. It creates a PDF and reports the missing glyph in the same run. That distinction matters in a conversion pipeline: receiving bytes, or seeing a page count greater than zero, does not establish that all requested characters are visible.

## Why are my PDF fonts not displaying correctly?

First check whether the renderer has a font containing the requested character. OneRender’s [PDF diagnostics documentation](https://recursiveai.org/onerender/docs/pdf/#diagnostics) says `MissingGlyph` means no registered font has that glyph. The glyph is not drawn, its advance is kept, and the text stays extractable. A visible gap and text that can still be extracted are therefore compatible outcomes.

Read the message before changing CSS sizes or page margins. When an optional fonts package would cover the character, the diagnostic names that package. When none covers it, the message identifies the uncovered character instead. The example uses the latter case deliberately, so its output is not a request to install a CJK or emoji package.

If the message recommends a package, add and register the appropriate fonts using the fonts recipe. Then rerun the same HTML and inspect the diagnostics again. Merely listing a family in `font-family` does not supply a missing font file. Font selection and character coverage are separate from the fact that a PDF file can embed the fonts it did use.

## Detect missing glyphs in code

Use the diagnostic kind as your program’s decision point, as in the variation. Message strings explain the particular problem to a person; `DiagnosticKind.MissingGlyph` lets an application distinguish missing characters from other rendering messages without depending on exact punctuation.

The documented reporting unit is one diagnostic per optional fonts package that would cover the character, and one per character no package covers. Do not treat the diagnostic count as a count of every visible blank in a document. Keep the original messages if you need to tell a caller what to correct.

A missing-glyph diagnostic does not stop the sample from writing its output stream. If your application must reject incomplete text, make that a separate application decision after conversion. For an HTTP endpoint, consider rendering into a memory stream first so you can inspect the result before sending the bytes.

## How do diagnostics differ from exceptions?

Construct the finished HTML, open a writable stream and call the stream overload shown above. Keep that stream alive until the call returns. The page count belongs to the completed conversion, and the diagnostics describe rendering decisions made during that operation.

Diagnostics and exceptions serve different purposes. A recoverable rendering issue can leave a usable PDF with warnings. Invalid options, cancellation or a conversion failure may instead throw. A missing-glyph check should supplement normal exception handling, not replace it. Image rendering is different again: the image convenience API reports no diagnostics, so use the PDF result for this particular inspection task.
