Sample code · C#
using System; using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; using SelectPdf.Universal; namespace SelectPdf.Samples.Pages { public class PdfAStandardsModel : PageModel { public void OnGet() { TxtUrl = "https://selectpdf.com"; DdlStandard = "PdfA3B"; } [BindProperty] public string TxtUrl { get; set; } [BindProperty] public string DdlStandard { get; set; } = "PdfA3B"; public List<SelectListItem> Standards { get; } = new List<SelectListItem> { new SelectListItem { Value = "PdfA", Text = "PDF/A-1b" }, new SelectListItem { Value = "PdfA2B", Text = "PDF/A-2b" }, new SelectListItem { Value = "PdfA3B", Text = "PDF/A-3b (allows embedded files)" }, new SelectListItem { Value = "PdfA3U", Text = "PDF/A-3u (Unicode mapping)" }, new SelectListItem { Value = "PdfA3A", Text = "PDF/A-3a (accessible - implies tagging)" }, new SelectListItem { Value = "PdfA4", Text = "PDF/A-4 (PDF 2.0)" }, new SelectListItem { Value = "PdfA4E", Text = "PDF/A-4e (PDF 2.0, engineering)" }, new SelectListItem { Value = "PdfA4F", Text = "PDF/A-4f (PDF 2.0, embedded files)" }, new SelectListItem { Value = "PdfX", Text = "PDF/X-1a:2001 (print production)" }, }; public IActionResult OnPost() { try { // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); converter.Options.NavigationTimeout = Startup.NavigationTimeout; // the standard the produced document conforms to converter.Options.PdfStandard = SampleForm.ParseEnum(DdlStandard, PdfStandard.PdfA3B); // the accessible levels are tagged documents, and a tagged document declares a title // and a language if (DdlStandard == "PdfA3A") { converter.Options.AccessibilityStandard = PdfUAStandard.UA1; converter.Options.Title = "SelectPdf - archived document"; converter.Options.Language = "en-US"; } // create a new pdf document converting an url PdfDocument doc = converter.ConvertUrl(TxtUrl); // save pdf document byte[] pdf = doc.Save(); // close pdf document doc.Close(); // return resulted pdf document FileResult fileResult = new FileContentResult(pdf, "application/pdf"); fileResult.FileDownloadName = "ArchivedDocument.pdf"; return fileResult; } catch (Exception ex) { // a document that cannot be produced to the chosen standard is refused with the reason; // show it on the page rather than as a server error ViewData["Message"] = "An error occurred: " + ex.Message; return Page(); } } } }