Set Profile = HtmlPdfProfile.PdfA2a. PDF/A-2a is an ISO 19005-2 archival format that preserves both how the pages look and the document’s tagged structure. No JavaScript runs.
dotnet add package RecursiveAI.OnePdf.Html.RenderRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
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 and dotnet run.
dotnet run prints:
Pages: 1Writes 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:
<!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:
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
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, 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.