Create PDF/UA and PDF/A Compliant Documents

HiQPdf HTML to PDF Converter can be configured to automatically generate PDF documents compliant with accessibility and archival standards by setting the PdfDocumentControlPdfStandard property. An object of PdfDocumentControl type is exposed by the HtmlToPdfDocument property

You can generate PDF documents compliant with PDF/UA-1, PDF/UA-2, PDF/A-2b, PDF/A-2a, PDF/A-3b, PDF/A-3u, PDF/A-3a, PDF/A-4, PDF/A-4f, WTPDF 1.0 or combinations of these standards

The PDF/UA standards make the document accessible to screen readers and assistive technologies, the PDF/A standards make it suitable for long-term archiving and WTPDF (Well-Tagged PDF) is the PDF Association specification for accessible and reusable PDF 2.0 documents, based on PDF/UA-2. Accessible documents are required by the European Accessibility Act for the documents that businesses deliver to consumers, such as invoices, statements and contracts

The converter builds the structure of the accessible document from the HTML: the headings, the paragraphs, the lists, the tables with their header cells, the links and the alternate text of the images carry over to the PDF, together with the document language and title

The following PDF standards are supported

The documents produced for these standards can be password protected and digitally signed like any other generated document. The PDF 2.0 documents are encrypted with AES 256 unless another algorithm is selected

Code Sample - Auto Create PDF/UA and PDF/A

C#
using System;
using System.IO;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using HiQPdf_Next_AspNetDemo.Models;

using HiQPdf.Next;

namespace HiQPdf_Next_AspNetDemo.Controllers
{
    public class CreatePdfUaAndPdfAController : Controller
    {
        IWebHostEnvironment m_hostingEnvironment;

        public CreatePdfUaAndPdfAController(IWebHostEnvironment hostingEnvironment)
        {
            m_hostingEnvironment = hostingEnvironment;
        }

        public IActionResult Index()
        {
            var model = SetViewModel();

            return View(model);
        }

        [HttpPost]
        public ActionResult ConvertToPdf(CreatePdfUaAndPdfAViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var errorMessage = ModelStateHelper.GetModelErrors(ModelState);
                throw new ValidationException(errorMessage);
            }

            // Set the serial number received after purchase to use the library in licensed mode; leave it commented for demo mode
            // Licensing.SerialNumber = "your-serial-number";

            // Create an HTML to PDF converter object with default settings
            HtmlToPdf htmlToPdfConverter = new HtmlToPdf();

            // Sets the PDF standard for the generated document
            // Leave as None to generate a plain PDF without an accessibility structure tree or archival metadata
            htmlToPdfConverter.Document.PdfStandard = model.PdfStandard;

            // The language of the document, a BCP 47 tag; it replaces the language declared by the HTML page.
            // Left empty, the language of the HTML page is used
            if (!string.IsNullOrWhiteSpace(model.DocumentLanguage))
                htmlToPdfConverter.Document.Properties.Language = model.DocumentLanguage;

            // PDF/A-4f is the PDF/A-4 variant for documents with embedded files and requires at least one
            if (model.PdfStandard == PdfStandard.PdfA4f || model.PdfStandard == PdfStandard.PdfUa2PdfA4f
                || model.PdfStandard == PdfStandard.Wtpdf1PdfA4f)
            {
                var textAttachment = PdfFileAttachment.FromFile(Path.Combine(m_hostingEnvironment.ContentRootPath,
                    "wwwroot", "DemoFiles", "Text", "Alphabet.txt"));
                textAttachment.MimeType = "text/plain";
                textAttachment.Description = "Sample text file";
                htmlToPdfConverter.Document.AddFileAttachment(textAttachment);
            }

            // convert HTML to PDF
            byte[] pdfBuffer = null;

            if (model.UrlOrHtmlCode == "ConvertUrl")
            {
                // convert URL to a PDF memory buffer
                string url = model.Url;

                pdfBuffer = htmlToPdfConverter.ConvertUrlToMemory(url);
            }
            else
            {
                // convert HTML code
                string htmlCode = model.HtmlCode;
                string baseUrl = model.BaseUrl;

                // convert HTML code to a PDF memory buffer
                pdfBuffer = htmlToPdfConverter.ConvertHtmlToMemory(htmlCode, baseUrl);
            }

            FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf");
            fileResult.FileDownloadName = "PdfStandards.pdf";

            return fileResult;
        }

        private CreatePdfUaAndPdfAViewModel SetViewModel()
        {
            var model = new CreatePdfUaAndPdfAViewModel();

            var contentRootPath = Path.Combine(m_hostingEnvironment.ContentRootPath, "wwwroot");

            HttpRequest request = ControllerContext.HttpContext.Request;
            UriBuilder uriBuilder = new UriBuilder();
            uriBuilder.Scheme = request.Scheme;
            uriBuilder.Host = request.Host.Host;
            if (request.Host.Port != null)
                uriBuilder.Port = (int)request.Host.Port;
            uriBuilder.Path = request.PathBase.ToString() + request.Path.ToString();
            uriBuilder.Query = request.QueryString.ToString();

            string currentPageUrl = uriBuilder.Uri.AbsoluteUri;
            string rootUrl = currentPageUrl.Substring(
                0, currentPageUrl.Length - "CreatePdfUaAndPdfA".Length);

            model.HtmlCode = System.IO.File.ReadAllText(Path.Combine(contentRootPath, "DemoFiles/Html/PDF_Standards.html"));
            model.BaseUrl = rootUrl + "DemoFiles/Html/";

            return model;
        }
    }
}

See Also