---
title: "onepdf-html"
url: https://recursiveai.org/onepdf-html/
description: "Convert between PDF and HTML in .NET, in both directions. PDF to semantic, reflowing HTML or fixed-layout HTML that looks like the page; HTML to a tagged PDF with PDF/UA-1 or PDF/A-2a; OCR for scanned pages; and the onepdf-html command. MIT or Apache-2.0. 1.0.0."
---

# onepdf-html

Convert between PDF and HTML in .NET, in both directions: semantic or fixed-layout HTML from a PDF, and a tagged PDF from HTML.

```sh
dotnet add package RecursiveAI.OnePdf.Html --version 1.0.0
```

- [Getting started](https://recursiveai.org/onepdf-html/docs/getting-started/)
- [Docs](https://recursiveai.org/onepdf-html/docs/)
- [GitHub](https://github.com/recursive-ai-oss/onepdf-html-csharp)
- [NuGet](https://www.nuget.org/packages/RecursiveAI.OnePdf.Html)

## A quick look

An HTML report becomes a PDF/UA-1 file, and the PDF becomes reflowing HTML again. The table comes back as a table, with its header row of `th` cells, from the PDF’s tags.

HTML to PDF is `RecursiveAI.OnePdf.Html.Render`; PDF to HTML is `RecursiveAI.OnePdf.Html`. The input is [report.html](https://recursiveai.org/onepdf-html/samples/report.html).

[Getting started](https://recursiveai.org/onepdf-html/docs/getting-started/)

*Program.cs · C#*

```
using System.Text.RegularExpressions;
using OnePdf.Html;
using OnePdf.Html.Render;
 
// HTML to a tagged PDF/UA-1 file
HtmlToPdf.ConvertFile("report.html", "report.pdf",
    new HtmlToPdfOptions { Profile = HtmlPdfProfile.PdfUA1 });
 
// and back to HTML: print the table, one row per line
string html = PdfHtml.Convert("report.pdf");
foreach (Match row in Regex.Matches(html, "<tr>.*?</tr>"))
{
    var cells = Regex.Matches(row.Value, "<(t[hd])[^>]*>(?:<[^>]+>)*([^<]*)");
    var text = cells.Select(c => c.Groups[2].Value);
    Console.WriteLine($"{cells[0].Groups[1]}: {string.Join(" | ", text)}");
}
```

*Output*

```
th: Collection | September | October
td: Fiction | 4,210 | 4,580
td: Nonfiction | 2,975 | 3,120
td: Children | 3,340 | 3,615
```

### PDF to semantic HTML

Semantic output is “clean, reflowing HTML in reading order: headings, paragraphs, lists, tables, figures, links and notes, built from the PDF’s tags or inferred from its layout.”

### PDF to fixed-layout HTML

Fixed-layout output “looks like the page: positioned, selectable text in the PDF’s own glyph shapes over vector graphics and images, one box per page.” The glyphs are WOFF2 subsets; vector content is SVG.

### HTML to PDF

“A string, file, stream or URL in, a tagged PDF out, with page size, margins, headers and footers, links, an outline, and PDF/UA-1 or PDF/A-2a.” Layout is [onerender](https://recursiveai.org/onerender/)’s.

### Scanned pages

`RecursiveAI.OnePdf.Html.Ocr` “recognises text on scans and on pages whose text layer is broken, in both PDF to HTML modes,” with [oneocr](https://recursiveai.org/oneocr/). Latin, Greek and Cyrillic are built in; add `RecursiveAI.OneOcr.Models.Cjk`, `.Arabic`, `.Hebrew` or `.Indic` for those scripts.

### Safe output

The HTML “never contains script and never refers to a remote resource. Nothing is fetched.” Only `http`, `https`, `mailto` and in-document links are kept. HTML to PDF runs no script and reads the network only for a URL input or when you turn it on.

### Command line

`onepdf-html` converts in both directions: “a PDF becomes HTML; an HTML file, a URL or standard input becomes a PDF.” It installs as a native executable on linux-x64, linux-arm64, osx-arm64 and win-x64.

```sh
dotnet tool install -g RecursiveAI.OnePdf.Html.Tool
```

## Compared with pdf2htmlEX

From the [README at v1.0.0](https://github.com/recursive-ai-oss/onepdf-html-csharp/blob/v1.0.0/README.md#comparison-with-pdf2htmlex) (README.md:126–145): “pdf2htmlEX is a native command-line program that makes fixed-layout HTML; OnePdf.Html is a managed library (and tool) with two output modes and the reverse direction.”

“Fixed layout, 100 pages of the 62 files in `testdata/eval/fixed.csv` (13 categories: text, multi-column, tables and math, forms, images, vector maps, transparency, Type 3, CJK, right-to-left, rotated, scans with a text layer, repaired broken files):”

| Quality (harness session) | OnePdf.Html | pdf2htmlEX |
|---|---|---|
| Visual similarity to the page render (SSIM, mean of pages; higher is better) | 0.980 | 0.887 |
| Ink that differs from the render, % (lower is better) | 1.4 | 26.1 |
| Text content error, % against the page’s text (lower is better) | 0.4 | 9.9 |
| Reading-order error, % (lower is better) | 0.7 | 18.5 |
| HTML per page, KiB (total bytes over total pages) | 41 | 147 |

| Speed (bench session) | OnePdf.Html | pdf2htmlEX |
|---|---|---|
| Conversion time, ms per page, median of the 62 files (mean in brackets) | 15 (30) | 80 (113) |
| Peak memory of one conversion, MiB, median of the files (largest) | 36 (137) | 32 (59) |

“The memory row is not a win: pdf2htmlEX’s resident set is a little smaller, because OnePdf.Html draws a page picture for anything a browser cannot express and holds it while the page is converted.”

“Numbers from one machine and one session are indicative of the ratio, not of any other machine.”

[The method and the semantic results](https://github.com/recursive-ai-oss/onepdf-html-csharp/blob/v1.0.0/README.md#comparison-with-pdf2htmlex)

## The packages

- **.Html**: `RecursiveAI.OnePdf.Html` is the PDF to HTML converter, built on [onepdf](https://recursiveai.org/onepdf/), [oneimage](https://recursiveai.org/oneimage/), [onefont](https://recursiveai.org/onefont/) and [onehtml](https://recursiveai.org/onehtml/). 1.0.0.
- **.Html.Ocr**: `RecursiveAI.OnePdf.Html.Ocr` is “a text source that recognises text on scanned pages and on pages with a broken text layer.” It brings oneocr and its models. 1.0.0.
- **.Html.Render**: `RecursiveAI.OnePdf.Html.Render` converts HTML to PDF. “A separate package, so PDF to HTML users do not get a layout engine and its fonts.” 1.0.0.
- **.Html.Tool**: `RecursiveAI.OnePdf.Html.Tool` is “the `onepdf-html` command, both directions,” with a framework-dependent build for platforms that have no native one. 1.0.0.
- **.NET**: .NET 10. “Pure managed code”, “NativeAOT- and trim-compatible, no native libraries.” All four packages share one version. MIT or Apache-2.0.

## Go further

- [GitHub](https://github.com/recursive-ai-oss/onepdf-html-csharp)
- [NuGet](https://www.nuget.org/packages/RecursiveAI.OnePdf.Html)
- [Getting started](https://recursiveai.org/onepdf-html/docs/getting-started/)
- [All docs](https://recursiveai.org/onepdf-html/docs/)
- [PDF to HTML](https://recursiveai.org/onepdf-html/docs/pdf-to-html/)
- [HTML to PDF](https://recursiveai.org/onepdf-html/docs/html-to-pdf/)
- [Command line](https://recursiveai.org/onepdf-html/docs/cli/)
- [Changelog](https://recursiveai.org/onepdf-html/docs/changelog/)
