Recursive AI

Render HTML to PDF/A-2a 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.

Render HTML directly to a tagged archival PDF with the PDF/A-2a profile. PDF/A is the ISO standard for long-term archiving; level “a” adds tagged structure to support accessibility.

Terminal
dotnet add package RecursiveAI.OneRender.Pdf

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using OneRender.Pdf;
 
string html =
    "<h1>Receipt</h1><p>Paid.</p>";
var options = new HtmlPdfOptions {
    Output = new PdfOutputOptions {
        Profile = PdfProfile.PdfA2a,
        Language = "en"
    }
};
File.WriteAllBytes("archive.pdf",
    HtmlPdf.ToPdf(html, options));
Console.WriteLine("Saved archive.pdf");

Writes archive.pdf. The snippet prints Saved archive.pdf.

Unzip the example, then dotnet run.

The full program

The full program supplies an English language and title in its inline HTML, then reads the saved file’s archival identification. If the file breaks the profile rules OnePdf checks, writing throws PdfRenderException listing the broken rules.

using OnePdf; comes from RecursiveAI.OnePdf, installed automatically as a dependency of RecursiveAI.OneRender.Pdf; no second install is needed.

C#
using OneRender.Pdf;
using OnePdf;
 
string html = "<html lang='en'><title>Archive</title><body><h1>Receipt</h1><p>Paid in full.</p></body></html>";
var options = new HtmlPdfOptions
{
    Output = new PdfOutputOptions { Profile = PdfProfile.PdfA2a }
};
File.WriteAllBytes("archive.pdf", HtmlPdf.ToPdf(html, options));
using var document = PdfDocument.Open("archive.pdf");
Console.WriteLine($"archive.pdf: {document.Pages.Count} page(s)");
Console.WriteLine($"PDF/A-{document.Xmp?.PdfAPart}{document.Xmp?.PdfAConformance}");
Text
archive.pdf: 1 page(s)
PDF/A-2A

Variations

Replace the full program’s options with these to request both PDF/A-2a and PDF/UA-1.

C#
var options = new HtmlPdfOptions {
    Output = new PdfOutputOptions {
        Profile = PdfProfile.PdfA2aAndUA1
    }
};

HTML to PDF · Accessible PDF

The short answer

Set HtmlPdfOptions.Output.Profile to PdfProfile.PdfA2a, render the HTML with HtmlPdf.ToPdf, and save the returned bytes. The PDF backend embeds the text fonts and writes a tagged document. The full example reads the PDF/A part and conformance level back from the saved XMP metadata: PDF/A-2A.

This is HTML-to-PDF generation, not conversion of an existing PDF. You control the source markup and styles before the PDF exists. Supply meaningful headings, readable text and the document language rather than trying to reconstruct them from a finished page image.

What is the difference between PDF/A-2a, PDF/A-2b and PDF/A-2u?

The Library of Congress’s PDF/A-2 description distinguishes three conformance levels:

  • 2b preserves visual appearance, without requiring the document’s structural or semantic properties.
  • 2u adds Unicode equivalents for all text to the level B requirements.
  • 2a satisfies all requirements, including the tagged structure needed to represent the document logically and support accessibility.

Choose the level required by the receiving archive. A visually correct PDF is not automatically level A, and a Unicode text mapping is not a substitute for document structure. Use meaningful headings and reading order in the HTML rather than replacing the document with a page image.

OneRender’s PdfProfile.PdfA2a requests level A; the profile enum does not offer separate PDF/A-2b or PDF/A-2u options. Its default is None, which does not identify the output as PDF/A. The full example reads the part and conformance from XMP, where the level appears as uppercase A.

The PDF output documentation explains that profile output is built in memory and re-saved with identification metadata. This differs from profile None, which streams pages as they are committed. The sample calls HtmlPdf.ToPdf(html, options), the overload that returns a byte[], before File.WriteAllBytes opens the destination file.

How do I check whether a file is really PDF/A-2a?

Use an outside PDF/A validator that supports ISO 19005-2 level A. Open the generated archive.pdf, select PDF/A-2a if the tool asks for a conformance profile, and inspect its conformance report. Keep the report with the exact file you checked; changing the file afterward requires another check. If an archive specifies a validation tool or acceptance procedure, follow that procedure.

The console output here is not a validation report. It reads pdfaid:part and pdfaid:conformance from XMP: the file’s declared identification, whose fields are described by the Library of Congress. We have not run an outside validator for this example.

The backend can also refuse the write with PdfRenderException when the file breaks the profile rules its PDF writer checks. That is distinct from outside validation. Treat a successful render, a metadata claim and a validator’s report as different pieces of information, not interchangeable results.

Can I create PDF/A and an accessible PDF together?

Use PdfA2aAndUA1 for the combined identification, as the variation shows. PdfA2a alone requests the archival profile; PdfUA1 alone requests the accessibility profile. These are separate choices in the public API. Keep tagging enabled for the profiles that require it.

The full receipt contains a title and language so the combined-profile variation has that information available. Richer documents need equally deliberate source semantics: headings should be headings, and text should not be replaced with decorative page images. Start with the simple receipt, then add your real markup and handle any reported profile failures before saving a production artifact.

All onerender recipes