EVO HTML to PDF Converter can be configured to automatically generate PDF documents compliant with accessibility and archival standards by setting the PdfDocumentOptionsPdfStandard property. An object of PdfDocumentOptions type is exposed by the HtmlToPdfConverterPdfDocumentOptions 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
Set the PdfDocumentOptionsPdfStandard property to PdfStandardPdfUa1 to create an accessible PDF/UA-1 document
Set it to PdfStandardPdfUa2 to create an accessible PDF/UA-2 document, based on PDF 2.0
Set it to PdfStandardPdfA2b to create a PDF/A-2b document for long-term archiving
Set it to PdfStandardPdfA2a to create a tagged PDF/A-2a document for accessible long-term archiving
Set it to PdfStandardPdfA3b to create a PDF/A-3b document for long-term archiving with embedded files of any type
Set it to PdfStandardPdfA3u to create a PDF/A-3u document for long-term archiving with Unicode text and embedded files of any type
Set it to PdfStandardPdfA3a to create a tagged PDF/A-3a document for accessible long-term archiving with embedded files of any type
Set it to PdfStandardPdfA4 to create a PDF/A-4 document, based on PDF 2.0, for long-term archiving
Set it to PdfStandardPdfA4f to create a PDF/A-4f document, based on PDF 2.0, for long-term archiving with embedded files of any type. PDF/A-4f requires at least one embedded file, added with PdfDocumentOptionsAddFileAttachment(PdfFileAttachment)
Set it to PdfStandardPdfUa1PdfA2b, PdfStandardPdfUa1PdfA2a or PdfStandardPdfUa1PdfA3a to create a document conforming to both PDF/UA-1 and the selected PDF/A level, for accessibility and long-term archiving. PDF/UA-1 with PDF/A-3a is the standard of the accessible electronic invoices described in the Create Electronic Invoices topic
Set it to PdfStandardPdfUa2PdfA2b, PdfStandardPdfUa2PdfA2a, PdfStandardPdfUa2PdfA4 or PdfStandardPdfUa2PdfA4f to create a document conforming to both PDF/UA-2 and the selected PDF/A level
Set it to PdfStandardWtpdf1 to create a WTPDF 1.0 (Well-Tagged PDF) document, which also conforms to PDF/UA-2
Set it to PdfStandardWtpdf1PdfA4 or PdfStandardWtpdf1PdfA4f to create a document conforming to WTPDF 1.0, PDF/UA-2 and PDF/A-4 or PDF/A-4f, for accessibility, reuse and long-term archiving
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
using System;
using System.IO;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using EvoPdf_Next_AspNetDemo.Models;
using EvoPdf_Next_AspNetDemo.Models.HTML_to_PDF;
// Use EVO PDF Namespace
using EvoPdf.Next;
namespace EvoPdf_Next_AspNetDemo.Controllers.HTML_to_PDF
{
public class Create_PdfUa_and_PdfAController : Controller
{
private readonly IWebHostEnvironment m_hostingEnvironment;
public Create_PdfUa_and_PdfAController(IWebHostEnvironment hostingEnvironment)
{
m_hostingEnvironment = hostingEnvironment;
}
public IActionResult Index()
{
var model = SetViewModel();
return View(model);
}
[HttpPost]
public ActionResult ConvertHtmlToPdf(Create_PdfUa_and_PdfA_ViewModel model)
{
if (!ModelState.IsValid)
{
var errorMessage = ModelStateHelper.GetModelErrors(ModelState);
throw new ValidationException(errorMessage);
}
// Set the license key received after purchase to use the library in licensed mode; leave it commented for demo mode
// Licensing.LicenseKey = "your-license-key";
// Create a HTML to PDF converter object with default settings
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();
// 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.PdfDocumentOptions.PdfStandard = model.PdfStandard;
// 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", "DemoAppFiles", "Input", "Text_Files", "Alphabet.txt"));
textAttachment.MimeType = "text/plain";
textAttachment.Description = "Sample text file";
htmlToPdfConverter.PdfDocumentOptions.AddFileAttachment(textAttachment);
}
byte[] outPdfBuffer = null;
if (model.HtmlPageSource == "Url")
{
string url = model.Url;
outPdfBuffer = htmlToPdfConverter.ConvertUrl(url);
}
else
{
string htmlWithForm = model.HtmlString;
string baseUrl = model.BaseUrl;
outPdfBuffer = htmlToPdfConverter.ConvertHtml(htmlWithForm, baseUrl);
}
// Send the PDF file to browser
FileResult fileResult = new FileContentResult(outPdfBuffer, "application/pdf");
fileResult.FileDownloadName = "PDF_Standards.pdf";
return fileResult;
}
private Create_PdfUa_and_PdfA_ViewModel SetViewModel()
{
var model = new Create_PdfUa_and_PdfA_ViewModel();
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 - "Create_PdfUa_and_PdfA".Length);
model.HtmlString = System.IO.File.ReadAllText(Path.Combine(contentRootPath, "DemoAppFiles/Input/HTML_Files/PDF_Standards.html"));
model.BaseUrl = rootUrl + "DemoAppFiles/Input/HTML_Files/";
return model;
}
}
}