ExpertPdf v22 is out, and the biggest change is where your HTML to PDF code can run. Until now, the ExpertPdf HTML to PDF Converter was a Windows library. With v22 comes ExpertPdf Anywhere, one .NET library with every ExpertPdf tool, for Windows, Linux and macOS, in Docker containers and in the cloud. This post walks through what that means in practice.
HTML to PDF on Linux in a few lines
ExpertPdf Anywhere renders HTML with Chromium 154, the engine of the Chrome browser, and the engine ships in the NuGet packages. Nothing is installed on the server, and on Linux no system package is needed. Add the package of your platform, which brings the ExpertPdf Anywhere library with it:
dotnet add package ExpertPdf.Anywhere.Linux dotnet add package ExpertPdf.Anywhere.Fonts
The fonts package matters on servers and containers without fonts: it brings fonts for every script, so pages in any language render. On Windows, use ExpertPdf.Anywhere.Windows; on a Mac, ExpertPdf.Anywhere.MacOS; on ARM64 Linux, ExpertPdf.Anywhere.Linux.Arm64.
The code is what you know from the classic converter, in the ExpertPdf.Anywhere.HtmlToPdf namespace:
using ExpertPdf.Anywhere.HtmlToPdf; var converter = new PdfConverter(); // converter.LicenseKey = "your license key"; // A4 pages, the page laid out in a 1024 pixels wide browser window converter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4; converter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait; converter.PageWidth = 1024; // Page numbers in the footer converter.PdfDocumentOptions.ShowFooter = true; converter.PdfFooterOptions.ShowPageNumber = true; converter.SavePdfFromUrlToFile("https://www.example.com/", "page.pdf");
By default the engine is loaded into your application and kept ready between conversions, so no process is started for each one, and 8 conversions run at the same time by default. Create one converter per conversion; the asynchronous methods, such as GetPdfBytesFromUrlAsync, take a cancellation token.
In a Docker container
A standard multi-stage Dockerfile is all it takes. The image needs no apt-get, no extra docker run options, no --no-sandbox, no GPU and no --shm-size:
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build WORKDIR /src COPY . . RUN dotnet publish MyApp.csproj -c Release -o /app FROM mcr.microsoft.com/dotnet/aspnet:10.0 WORKDIR /app COPY --from=build /app . ENV ASPNETCORE_URLS=http://+:8080 EXPOSE 8080 ENTRYPOINT ["dotnet", "MyApp.dll"]
Any glibc-based .NET image works: the default Debian images, Ubuntu, and Amazon Linux with a self-contained publish. Alpine images convert through the ExpertPdf engine container (the remote engine) instead. The same application runs on Azure App Service, Azure Functions and Container Apps, AWS Lambda, Elastic Beanstalk, ECS and EKS, and Google Cloud Run; the cloud deployment guides have a tested setup for each.
Accessible and archivable PDF from HTML
A converted page can be a tagged, accessible PDF/UA document, with the headings, lists, tables and reading order that screen readers and other assistive technology use:
using System.IO; using ExpertPdf.Anywhere.HtmlToPdf; var converter = new PdfConverter(); // A tagged, accessible PDF/UA-1 document converter.AccessibilityStandard = PdfUAStandard.Pdf_UA_1; converter.Language = "en-US"; converter.PdfDocumentInfo.Title = "Invoice 1001"; string html = "<h1>Invoice 1001</h1><table><tr><th>Item</th><th>Amount</th></tr>" + "<tr><td>License</td><td>700.00</td></tr></table>"; // The base URL resolves the relative images and style sheets of the HTML byte[] pdf = converter.GetPdfBytesFromHtmlString(html, "https://www.example.com/"); File.WriteAllBytes("invoice.pdf", pdf);
PDF/UA-2 is there too, and PdfStandardSubset produces PDF/A-1, 2, 3 and 4 for long-term archiving, and ZUGFeRD and Factur-X electronic invoices from an HTML invoice.
Word, Excel and PowerPoint to PDF, and back
ExpertPdf Anywhere also converts Office documents, without Microsoft Office, on every platform. Word (DOCX, DOC, RTF, templates, Markdown), Excel (XLSX, XLS, CSV) and PowerPoint (PPTX, as slides, notes pages or handouts) go to PDF:
using WordToPdf = ExpertPdf.Anywhere.WordToPdf; using ExcelToPdf = ExpertPdf.Anywhere.ExcelToPdf; using PowerPointToPdf = ExpertPdf.Anywhere.PowerPointToPdf; // Word: the page sizes and margins of the document var word = new WordToPdf.PdfConverter(); word.SavePdfFromWordFileToFile("report.docx", "report.pdf"); // Excel: each sheet as Excel prints it, all columns on one page var excel = new ExcelToPdf.PdfConverter(); excel.Layout = ExcelToPdf.ExcelLayout.FitAllColumnsOnOnePage; excel.SavePdfFromExcelFileToFile("sales.xlsx", "sales.pdf"); // PowerPoint: handouts with four slides on a page var powerPoint = new PowerPointToPdf.PdfConverter(); powerPoint.Publish = PowerPointToPdf.PowerPointPublish.Handouts; powerPoint.SlidesPerHandout = 4; powerPoint.SavePdfFromPowerPointFileToFile("deck.pptx", "deck.pdf");
And the other way: PDF to Word writes an editable document, PDF to Excel turns the tables of a PDF into cells with real numbers and dates, and PDF to PowerPoint makes a slide of each page.
Coming from the classic components
Anywhere keeps the classes of the classic components: PdfConverter for HTML to PDF, Document for the PDF Creator, PDFMerge, PdfSecurityManager and the rest, in namespaces under ExpertPdf.Anywhere. The migration guide lists what changes when you move to Anywhere.
The classic components continue on Windows, and v22 brings them a lot too:
- The HTML to PDF Converter 22.0 has a new Chromium rendering engine (CEF 154) next to Blink, updated to Chromium 148, tagged PDF/UA-1 output, PDF/A-2 and PDF/A-3, a time limit for one conversion, and asynchronous methods with cancellation.
- The PDF Creator 22.0 builds tables of contents with page numbers, tagged PDF/UA documents, PDF/A-2 and PDF/A-3 with associated files, and ZUGFeRD and Factur-X invoices.
- The PDF Viewer 10.0 is built on WebView2 and PDF.js, with no Adobe Reader, for Windows Forms, WPF, ASP.NET and ASP.NET Core.
The full list of changes is in the version history and the ExpertPdf Anywhere release notes.
Licenses
Version 22.0 needs a version 22 license key. ExpertPdf Anywhere has its own license, and owners of an ExpertPdf Toolkit or ExpertComponents Toolkit Total license with a valid key get it for free. Every component can be tried in evaluation mode; see pricing and the downloads.
Try it
The online samples run every feature, with their source code, and the documentation covers the whole API. Start with cross-platform HTML to PDF, or read the release announcement for the complete list.