---
title: "Convert HTML to PDF/A-2a in C#"
url: https://recursiveai.org/onepdf-html/cookbook/convert-html-to-pdfa/
description: "Convert HTML to PDF/A-2a in C# with OnePdf.Html. Set the archival profile, keep the document structure, and run a .NET 10 example with sample HTML."
version: "1.0.0"
---

# Convert HTML to PDF/A-2a in C#

**OnePdf.Html** is a free, open-source .NET library from Recursive AI that converts PDF to HTML and HTML to PDF. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OnePdf.Html.Render) · [GitHub](https://github.com/recursive-ai-oss/onepdf-html-csharp) · [Docs](https://recursiveai.org/onepdf-html/docs/) · [Download example (.zip)](https://recursiveai.org/onepdf-html/cookbook/convert-html-to-pdfa/convert-html-to-pdfa.zip)

Set `Profile = HtmlPdfProfile.PdfA2a`. [PDF/A-2a](https://www.loc.gov/preservation/digital/formats/fdd/fdd000320.shtml) is an ISO 19005-2 archival format that preserves both how the pages look and the document’s tagged structure. No JavaScript runs.

```shell
dotnet add package RecursiveAI.OnePdf.Html.Render
```

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

```csharp
using OnePdf.Html.Render;

var result = HtmlToPdf.ConvertFile(
    "report.html", "archive.pdf",
    new() { Profile = HtmlPdfProfile.PdfA2a });
Console.WriteLine($"Pages: {result.PageCount}");
```

Paste the code above into Program.cs of a new `dotnet new console` project and `dotnet run`, or unzip [the example](https://recursiveai.org/onepdf-html/cookbook/convert-html-to-pdfa/convert-html-to-pdfa.zip) and `dotnet run`.

`dotnet run` prints:

```text
Pages: 1
```

Writes `archive.pdf`. The input is `report.html`, included in the example ZIP. If you’re pasting the C# into a new project, save this HTML as `report.html` next to `Program.cs`:

```html
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>River level report</title>
<h1>River level report</h1>
<p>The river stood at 2.4 meters on May 1.</p>
</html>
```

The file takes its title from `<title>` and its language from `<html lang="en">`. If the output would break a rule of the requested profile, `ConvertFile` throws `HtmlToPdfException` with `Failure` set to `ProfileViolation` and does not write the PDF.

## Variations

**Set the title and language from C#.** With the same `using` and `report.html`, replace the conversion and print lines with:

```csharp
var options = new HtmlToPdfOptions
{
    Profile = HtmlPdfProfile.PdfA2a,
    Title = "May river measurements",
    Language = "en"
};
HtmlToPdf.ConvertFile("report.html", "may.pdf", options);
```

This writes `may.pdf` with “May river measurements” as its document title, without changing the visible heading.

## Related recipes

- [Add PDF bookmarks from HTML headings](https://recursiveai.org/onepdf-html/cookbook/add-bookmarks-from-html-headings-to-pdf/)
- [Convert an existing PDF to PDF/A](https://recursiveai.org/onepdf/cookbook/convert-pdf-to-pdfa/)

## The short answer

Set `Profile` to `HtmlPdfProfile.PdfA2a` in `HtmlToPdfOptions`, then pass the options to `HtmlToPdf.ConvertFile` with the input HTML and output PDF paths. Leave `Tagged` at its default of `true`. Give the HTML a document title and language, or specify them in the options if you don’t control the template. The package for this direction is `RecursiveAI.OnePdf.Html.Render`.

## What is PDF/A-2a?

According to the [Library of Congress format description](https://www.loc.gov/preservation/digital/formats/fdd/fdd000320.shtml), PDF/A-2a is level A of ISO 19005-2, a standard for preserving PDF documents. Level B keeps the visual presentation. Level U also requires Unicode equivalents for text. Level A goes further by preserving the document’s logical structure. In the example, “River level report” isn’t just large text: it starts as an `h1` and the converter can write it as a heading in the PDF’s tag structure.

## Why doesn’t the PDF title match the file name?

The output path names the file on disk. The HTML `<title>` names the document in its metadata. The visible heading comes from `<h1>`. These are three different values: in the variation, the file is `may.pdf`, its metadata title is “May river measurements,” and its heading is still “River level report.” Set `Title` to change the metadata without editing the source. Likewise, use the root element’s `lang` for the main language, or set `Language` explicitly when the source doesn’t specify it. The example uses `en` for English.

## What’s the difference between PDF/A and PDF/UA?

PDF/A addresses long-term preservation. PDF/UA addresses accessibility. Both use document structure, but asking for PDF/A-2a is not the same as asking for PDF/UA-1. Choose the profile the person receiving the file asks for. If you only need a tagged PDF without either designation, the converter’s default profile is `None`. The profile choices and their requirements are in the [HTML-to-PDF guide](https://recursiveai.org/onepdf-html/docs/html-to-pdf/#pdfua-and-pdfa).
