Cross-Platform Library (SelectPdf.Universal) - Linux, macOS (Apple Silicon), Docker, .NET Standard 2.0 - .NET 10 | |
SelectPdf.Universal is the cross-platform edition of the SelectPdf library. It runs on Windows, Linux and macOS (including Docker containers) on modern .NET, and keeps the classes and members of this library. Code written against Select.Pdf moves over with mechanical changes - new package references, the SelectPdf.Universal namespace and SelectPdf's own drawing types instead of System.Drawing - see Migrating Code below.
Use this library (Select.Pdf) for Windows-only .NET Framework / .NET applications. Use SelectPdf.Universal when the application must run on Linux or macOS, in Docker containers, or when the same code base must be deployable on more than one operating system.
HTML to PDF and HTML to image conversion with a Chromium-based rendering engine - full HTML5, CSS3, web fonts and JavaScript support (the same engine family as the Chromium engine in this library).
PDF creation and editing - pages, text, images, vector graphics, links, annotations, headers and footers, watermarks, templates, page numbering.
Working with existing PDFs - load, merge, resize, encrypt (up to AES-256), digitally sign and validate signatures, fill AcroForms, redact (content is removed from the file), PDF portfolios, compression.
Word to PDF conversion - Word documents and templates (DOCX, DOCM, DOTX, DOTM, DOC, DOT), RTF, WordML, HTML, Markdown and text, with the same headers, footers, security and standards options as HTML to PDF.
Standards - PDF/A (1b / 2b / 3b / 3u / 3a / 4 / 4e / 4f), PDF/X-1a, tagged / accessible PDF (PDF/UA-1 and PDF/UA-2), ZUGFeRD / Factur-X invoices.
Asynchronous conversion with cancellation. By default 8 conversions run at once in one process; HtmlToPdfOptions.MaximumConcurrentConversions changes the limit.
PDF to text and PDF to image conversion and text search.
Bundled fonts - the Liberation Sans, Serif and Mono families (metric-compatible with Arial, Times New Roman and Courier New) ship with the library, so text renders correctly even on minimal Linux images or containers with no fonts installed.
No System.Drawing dependency - drawing-related types (colors, points, sizes) come from a lightweight SelectPdf.Universal.Drawing namespace included in the library.
A typical installation is two steps: install one main library package, then one native engine package matching the deployment platform.
1. Main library packages (install one)
The full cross-platform library, AnyCPU. Targets .NET Standard 2.0 (usable from .NET Framework 4.6.1+, .NET Core 2.0+ and .NET 5+), with dedicated builds for .NET 8 and .NET 10. The complete feature set listed above.
The free cross-platform Community Edition - HTML to PDF conversion only, generates PDF documents up to 5 pages long.
https://www.nuget.org/packages/SelectPdf.HtmlToPdf.Universal/
2. Native engine packages (install the one matching the deployment platform; several can be installed side by side for multi-platform publishing)
Rendering engines for Windows, x64.
https://www.nuget.org/packages/SelectPdf.Universal.Native.win-x64/
Rendering engines for Windows, x86.
https://www.nuget.org/packages/SelectPdf.Universal.Native.win-x86/
Rendering engines for Linux, x64.
https://www.nuget.org/packages/SelectPdf.Universal.Native.linux-x64/
Rendering engines for Linux, ARM 64-bit.
https://www.nuget.org/packages/SelectPdf.Universal.Native.linux-arm64/
Rendering engines for macOS on Apple Silicon (ARM 64-bit), macOS 12 (Monterey) or newer.
https://www.nuget.org/packages/SelectPdf.Universal.Native.osx-arm64/
Windows (x64 / x86) - full feature set.
Linux (x64 / arm64) - full feature set, including minimal server images and Docker containers with no extra OS packages (the native engine package bundles everything, and rendering is headless - no X server needed).
macOS (Apple Silicon) - full feature set, including HTML to PDF and PDF to text / image. Requires macOS 12 (Monterey) or newer, and the engines link only macOS system frameworks, so there is nothing extra to install. On Intel Macs the PDF creation and manipulation features work, but the engines are not available - no osx-x64 package is produced.
The managed library is platform-neutral (AnyCPU). The Chromium engine runs inside the application when the native package matches the architecture of the application's process (win-x86 for a 32-bit Windows process), and in a separate process otherwise - so on Windows a 32-bit or a 64-bit application can use either the win-x86 or the win-x64 package. The native package must still match the operating system and the processor family: an x64 package does not run on an Arm64 machine.
Linux images must be glibc-based - glibc 2.30 or newer, which every mainstream distribution released since about 2020 provides (Ubuntu 20.04+, Debian 11+, RHEL 9+). Alpine images are built on musl and are not supported.
Chromium-based rendering is processor bound - allow at least 1 core and 2 GB of RAM per process or container, and prefer 2 or more cores when conversion latency matters.
Hosted platforms: Azure App Service on Windows and on Linux (Basic plan or above), Azure Container Apps, Azure Kubernetes Service, and Azure Functions on an App Service or Premium plan. See Deployment to Microsoft Azure.
For container deployment details (Linux and Windows containers), see Deployment to Docker.
SelectPdf.Universal keeps the classes, members and overloads of this library wherever they could be kept, so migration is mostly mechanical:
Replace the Select.Pdf, Select.Pdf.x64, Select.Pdf.NetCore or Select.Pdf.NetCore.x64 package and the Chromium or Blink companion packages with SelectPdf.Universal plus the matching SelectPdf.Universal.Native.<rid> package. Remove any direct reference to Select.Pdf.dll, the engine files the project carries (Select.Html.dep, Select.Tools.dep and the engine folders) and any build step that copies them - the native package deploys its files itself.
Change using SelectPdf; to using SelectPdf.Universal; (and Imports SelectPdf to Imports SelectPdf.Universal). The class names stay the same; the namespace changed.
Replace System.Drawing types in SelectPdf calls: colors with PdfColor (or SelectPdf.Universal.Drawing.Color), points, rectangles and sizes with the types of the SelectPdf.Universal.Drawing namespace, System.Drawing.Font with PdfFont or PdfSystemFont, and images with a Stream or a byte[]. HtmlToImage returns the encoded image as a byte[], and PdfRasterizer returns one byte[] per page (a single one for TIFF).
Remove the engine selection: SelectPdf.Universal renders with Chromium only, so the WebKit, WebKit Restricted and Blink engines and their settings are gone, and CefEnginePath is named ChromiumEnginePath. An application that rendered with the default WebKit engine should review its output: the layout, page breaks and page count follow the Chromium engine.
Check the fonts: an installed font is found by its exact family name on the machine the application runs on, and Windows fonts such as Arial are usually not installed on Linux servers or in containers. The bundled Liberation Sans, Serif and Mono families are available everywhere.
Replace PdfMergeManager with PdfDocument.Append. PdfPrinter is not available (it relied on Windows-only printing), and the Select.Pdf.Extras add-on has no counterpart.
Keep the license key: SelectPdf.Universal reads GlobalProperties.LicenseKey in the same format and accepts keys issued for version 26 or later.
The SelectPdf.Universal documentation has the complete list - every removed or renamed member, how fonts are found on each platform, and the defaults that changed (the engine runs inside the application when the native package matches the process architecture, conversions run 8 at a time, the HTTP cache is kept between conversions, and encryption uses AES-256) - in its Migrating to SelectPdf.Universal topic. The cross-platform library is presented at https://selectpdf.com/pdf-library-cross-platform/.