SelectPdf.Universal
26.5.0
Prefix Reserved
dotnet add package SelectPdf.Universal --version 26.5.0
NuGet\Install-Package SelectPdf.Universal -Version 26.5.0
<PackageReference Include="SelectPdf.Universal" Version="26.5.0" />
<PackageVersion Include="SelectPdf.Universal" Version="26.5.0" />
<PackageReference Include="SelectPdf.Universal" />
paket add SelectPdf.Universal --version 26.5.0
#r "nuget: SelectPdf.Universal, 26.5.0"
#:package SelectPdf.Universal@26.5.0
#addin nuget:?package=SelectPdf.Universal&version=26.5.0
#tool nuget:?package=SelectPdf.Universal&version=26.5.0
SelectPdf Library for .NET — Cross-Platform (Windows, Linux, macOS)
SelectPdf is a professional PDF library for creating, writing, editing and reading PDF files entirely in C#/VB.NET — no Adobe Acrobat required. It includes a state-of-the-art HTML to PDF converter built on Chromium (HTML5, CSS3, web fonts, modern JavaScript) and a Word to PDF converter (DOCX, DOC, RTF and more).
This package is cross-platform: it runs on Windows (x64, x86), Linux (x64, ARM64) and macOS (Apple Silicon), on .NET 10, .NET 9, .NET 8 and .NET Standard 2.0 (consumable from .NET Framework 4.6.1+). It runs in Docker containers and on Microsoft Azure, Amazon Web Services and Google Cloud. Verified with the .NET 11 release candidate (RC 1) on Windows x64, Linux x64 and ARM64, and macOS.
Installation
dotnet add package SelectPdf.Universal
# engine: win-x64, win-x86, linux-x64, linux-arm64 or osx-arm64
dotnet add package SelectPdf.Universal.Native.win-x64
The managed SelectPdf.Universal package is AnyCPU and works on every platform (the assembly is SelectPdf.Universal.dll, namespace SelectPdf.Universal). Add the SelectPdf.Universal.Native.<rid> package that matches your runtime: it deploys the Chromium engine (HTML to PDF / HTML to image) and the native PDF tool (PDF to text / PDF to image) next to your application.
| Native package | Runtime |
|---|---|
SelectPdf.Universal.Native.win-x64 |
Windows, 64-bit process |
SelectPdf.Universal.Native.win-x86 |
Windows, 32-bit process |
SelectPdf.Universal.Native.linux-x64 |
Linux x64 (glibc 2.30+) |
SelectPdf.Universal.Native.linux-arm64 |
Linux ARM64 (glibc 2.30+) |
SelectPdf.Universal.Native.osx-arm64 |
macOS 13+ on Apple Silicon |
For an application that runs on one platform, one package installs both: SelectPdf.Universal.Windows (Windows x64), SelectPdf.Universal.Linux, SelectPdf.Universal.Linux.Arm64 or SelectPdf.Universal.MacOS. Reference one of them or the two packages above, not both.
Quick start
HTML to PDF
using SelectPdf.Universal;
HtmlToPdf converter = new HtmlToPdf();
converter.Options.PdfPageSize = PdfPageSize.A4;
converter.Options.MarginTop = 20;
converter.Options.MarginBottom = 20;
using PdfDocument doc = converter.ConvertUrl("https://selectpdf.com");
// or: converter.ConvertHtmlString("<h1>Hello</h1>", baseUrl);
doc.Save("page.pdf");
Asynchronous conversion
HtmlToPdf converter = new HtmlToPdf();
using PdfDocument doc = await converter.ConvertUrlAsync(
"https://selectpdf.com", cancellationToken);
doc.Save("page.pdf");
HTML to PDF in an ASP.NET Core endpoint
using SelectPdf.Universal;
var app = WebApplication.CreateBuilder(args).Build();
// POST an HTML string, get a PDF back
app.MapPost("/pdf", async (HttpRequest request) =>
{
string html = await new StreamReader(request.Body).ReadToEndAsync();
HtmlToPdf converter = new HtmlToPdf();
converter.Options.PdfPageSize = PdfPageSize.A4;
using PdfDocument doc = await converter.ConvertHtmlStringAsync(html);
byte[] pdf = doc.Save();
return Results.File(pdf, "application/pdf", "document.pdf");
});
app.Run();
Word to PDF
WordToPdf converter = new WordToPdf();
// optional: archival output
converter.Options.PdfStandard = PdfStandard.PdfA2B;
using PdfDocument doc = converter.ConvertFile("contract.docx");
doc.Save("contract.pdf");
Create a PDF from scratch
using PdfDocument doc = new PdfDocument();
PdfPage page = doc.AddPage();
PdfFont font = doc.Fonts.Add(PdfStandardFont.Helvetica);
font.Size = 20;
page.Add(new PdfTextElement(50, 50, "Hello world!", font));
// html, images, shapes, links and bookmarks can be added too
page.Add(new PdfHtmlElement(50, 100, 400,
"<p>Some <b>html</b> content</p>", null));
doc.Save("hello.pdf");
Redact content
using PdfRedactionManager redaction = new PdfRedactionManager();
redaction.Load("statement.pdf");
redaction.OverlayText = "[REDACTED]";
// text
redaction.AddRedaction("John Smith", false, true);
// pattern
redaction.AddRedaction(
new System.Text.RegularExpressions.Regex(@"\d{3}-\d{2}-\d{4}"));
// the content is removed from the file, not just covered
redaction.Save("statement-redacted.pdf");
Sign and validate signatures
using PdfSecurityManager signer = new PdfSecurityManager();
signer.Load("contract.pdf");
signer.Sign("certificate.pfx", "pfxPassword");
signer.Save("contract-signed.pdf");
using PdfSecurityManager validator = new PdfSecurityManager();
validator.Load("contract-signed.pdf");
foreach (var result in validator.ValidateSignatures())
Console.WriteLine($"{result.SignerName}: {result.Status}");
Encrypt, merge, accessibility and archiving
using PdfDocument doc = new PdfDocument("report.pdf");
doc.Append("appendix.pdf"); // merge
doc.Security.OwnerPassword = "owner"; // AES-256 by default
doc.Security.UserPassword = "user";
doc.Security.CanCopyContent = false;
doc.Save("report-protected.pdf");
HtmlToPdf converter = new HtmlToPdf();
converter.Options.PdfStandard = PdfStandard.PdfA4; // PDF/A-4
// tagged, PDF/UA-2
converter.Options.AccessibilityStandard = PdfUAStandard.UA2;
converter.Options.Title = "Annual report";
converter.Options.Language = "en-US";
PDF to text and PDF to image
using PdfToText pdfToText = new PdfToText();
pdfToText.Load("document.pdf");
string text = pdfToText.GetText();
using PdfRasterizer rasterizer = new PdfRasterizer();
rasterizer.Load("document.pdf");
byte[][] pngPages = rasterizer.ConvertToImages();
Main Features
PDF documents
- Generate PDF documents from scratch; load, modify and save existing PDFs
- Page elements: text, images (PNG, JPEG, GIF, BMP, WebP, TIFF), HTML, HTML rendered as images, Word content, shapes, links, attachments, notes
- Reusable templates, headers and footers (also per page), watermarks and stamps, page numbering, bookmarks, page rotation
- Merge PDF documents; resize and reflow existing pages; PDF portfolios; open actions
- AcroForm filling and flattening
- Redaction: remove text (by value or regular expression), images, graphics, links and form fields from marked areas, optionally with an overlay label
- Compression of images, content streams and fonts
- PDF to text (extract, search, text in a region) and PDF to image (PNG, JPEG, BMP, GIF, TIFF)
HTML to PDF converter (Chromium)
- Convert any web page or HTML string to PDF, synchronously or asynchronously with cancellation
- Page size, orientation, margins, content resizing, page breaks, repeated table headers,
@mediascreen and print - HTML headers and footers, automatic bookmarks, internal and external links, table of contents, web element locations
- HTTP headers, cookies, POST data, authentication, login forms, proxy servers
- Conversion delay, navigation timeout, lazy image loading, JavaScript control, startup and post-loading scripts, custom CSS, element clicks
- Partial conversion (CSS selector), hidden elements, single-page PDF output
- HTML to image (PNG) converter
- Up to 8 conversions run concurrently (configurable)
Word to PDF converter
- DOCX, DOCM, DOTX, DOTM, DOC, DOT, RTF, TXT, WordML, HTML and Markdown input, encrypted documents included
- Keep the document's own page sizes or reflow onto the page size and margins you choose
- Outline from headings or Word bookmarks; headers, footers, security, PDF/A and PDF/UA output like the HTML converter
- Word content in PDF pages, headers and footers
Security and signatures
- RC4, AES and AES-GCM encryption, up to 256-bit keys (AES-256 by default), granular permissions, optional unencrypted XMP metadata
- Digital signatures (SHA-256) with visible appearance and RFC-3161 time stamps
- Signature validation: integrity, trust chain, coverage, time stamp and revocation status
Standards and accessibility
- PDF/A-1b, PDF/A-2b, PDF/A-3b, PDF/A-3u, PDF/A-3a, PDF/A-4, PDF/A-4e, PDF/A-4f and PDF/X-1a
- Tagged, accessible PDF: PDF/UA-1 and PDF/UA-2, from HTML, from Word and from scratch
- PDF/A-3 associated files; ZUGFeRD / Factur-X electronic invoices; custom XMP metadata schemas
Docker
The Linux engine packages bundle the Chromium libraries, so a Docker image needs no apt-get lines. Reference SelectPdf.Universal.Native.linux-x64 (or linux-arm64 for an ARM64 image) and build with the official .NET images:
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY . .
RUN dotnet publish -c Release -o /app
FROM mcr.microsoft.com/dotnet/aspnet:10.0
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "YourApp.dll"]
Reference one engine package per build: the packages install into the same folder, so a project that develops on Windows and deploys to Linux picks the package by runtime, for example with a Condition on $(RuntimeIdentifier).
Deployment notes
- Linux: the native packages bundle the Chromium shared libraries, so conversions run on minimal distributions and in containers without
apt-get. Requires glibc 2.30+ (Debian 11+, Ubuntu 20.04+, RHEL 9+). Alpine (musl) is supported through the remote engine: reference SelectPdf.Universal alone and setRenderingEngine.ChromiumRemote. - Docker: the official .NET images work as they are on Linux, with no
--shm-sizeor GPU; Windows containers need Windows Server Core with the core Windows fonts installed. - Azure: App Service (Basic plan or above) and Azure Functions on a Dedicated or Premium plan, on Windows and Linux.
- Cloud: step-by-step guides for Azure App Service, Azure Functions (Dedicated and Premium plans), Azure Container Apps, AWS Lambda (container image, x64 and arm64), AWS Elastic Beanstalk and Google Cloud Run.
- Fonts: Linux hosts and container images often have no fonts, and the fonts built into the library cover Latin scripts only. Add
SelectPdf.Universal.Fonts(Noto fonts for every script, copied next to the application on Linux and macOS) to render every language; your own fonts go in afontsfolder next to the application, on every platform. - Engine hosting: the Chromium engine runs inside your application when the native package matches your process architecture (a 32-bit Windows process, such as a default Windows App Service worker, uses
win-x86); with another package, conversions run in a separate engine process automatically. SetGlobalProperties.ChromiumEngineHostMode = ChromiumEngineHostMode.OutOfProcessto run every conversion in its own engine process. - Native debug symbols: SkiaSharp 3.119.2 and later ship
libSkiaSharp.pdb/libHarfBuzzSharp.pdb(about 300 MB for the Windows architectures) as runtime files, which the application never uses (SkiaSharp #3519). This package leaves them out of your build and publish output and your.deps.json; set<SelectPdfKeepNativeSymbols>true</SelectPdfKeepNativeSymbols>in your project to keep them.
Migrating to SelectPdf.Universal
SelectPdf.Universal is the cross-platform successor of the Windows-only Select.Pdf / Select.Pdf.NetCore packages. It keeps their classes and members, so porting is mostly mechanical:
- Replace the
Select.Pdf*package references (and the Chromium / Blink companion packages) withSelectPdf.Universalplus aSelectPdf.Universal.Native.<rid>package, and removeSelect.Html.dep,Select.Tools.depand the old engine folders from the project. - Change
using SelectPdf;tousing SelectPdf.Universal;. - Replace
System.Drawingtypes:PdfColorfor colors,SelectPdf.Universal.Drawingfor points, rectangles and sizes,PdfFont/PdfSystemFontfor fonts,Streamorbyte[]for images (HtmlToImageandPdfRasterizerreturn encoded images asbyte[]). - HTML is rendered with Chromium only: remove WebKit / Blink engine selection and settings, rename
CefEnginePathtoChromiumEnginePath, and review the output of pages that rendered with the WebKit default. - Use
PdfDocument.Appendinstead ofPdfMergeManager.PdfPrinterand theSelect.Pdf.Extrasadd-on have no counterpart.
License keys issued for version 26 or later keep working. The documentation's Migrating to SelectPdf.Universal topic lists every change, the defaults that differ and how fonts are found on each platform.
Documentation & Support
- Documentation: https://selectpdf.com/pdf-library/
- Website: https://selectpdf.com/
- Community Edition (free HTML to PDF converter, up to 5 pages): https://www.nuget.org/packages/SelectPdf.HtmlToPdf.Universal
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- BitMiracle.LibTiff.NET (>= 2.4.649)
- HarfBuzzSharp (>= 8.3.1.5)
- HarfBuzzSharp.NativeAssets.Linux (>= 8.3.1.5)
- Newtonsoft.Json (>= 13.0.3)
- SkiaSharp (>= 3.119.4)
- SkiaSharp.HarfBuzz (>= 3.119.4)
- SkiaSharp.NativeAssets.Linux.NoDependencies (>= 3.119.4)
- System.Text.Encoding.CodePages (>= 4.4.0)
-
net10.0
- BitMiracle.LibTiff.NET (>= 2.4.649)
- HarfBuzzSharp (>= 8.3.1.5)
- HarfBuzzSharp.NativeAssets.Linux (>= 8.3.1.5)
- Newtonsoft.Json (>= 13.0.3)
- SkiaSharp (>= 3.119.4)
- SkiaSharp.HarfBuzz (>= 3.119.4)
- SkiaSharp.NativeAssets.Linux.NoDependencies (>= 3.119.4)
-
net8.0
- BitMiracle.LibTiff.NET (>= 2.4.649)
- HarfBuzzSharp (>= 8.3.1.5)
- HarfBuzzSharp.NativeAssets.Linux (>= 8.3.1.5)
- Newtonsoft.Json (>= 13.0.3)
- SkiaSharp (>= 3.119.4)
- SkiaSharp.HarfBuzz (>= 3.119.4)
- SkiaSharp.NativeAssets.Linux.NoDependencies (>= 3.119.4)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on SelectPdf.Universal:
| Package | Downloads |
|---|---|
|
SelectPdf.Universal.Windows
The SelectPdf PDF library for .NET on Windows x64. This package contains no code: it installs SelectPdf.Universal (HTML to PDF and Word to PDF conversion, PDF creation and editing, redaction, digital signatures, PDF/A and PDF/UA) together with the Chromium engine package for win-x64. For a 32-bit process, use SelectPdf.Universal with SelectPdf.Universal.Native.win-x86. |
|
|
SelectPdf.Compat.WkHtmlToPdfDotNet.Licensed
The Haukcode.WkHtmlToPdfDotNet API (IConverter, SynchronizedConverter, HtmlToPdfDocument, GlobalSettings, ObjectSettings, CoverSettings) on the licensed SelectPdf.Universal library: Chromium rendering with no page limit, instead of wkhtmltopdf. The same code as the free SelectPdf.Compat.WkHtmlToPdfDotNet package, for applications with a SelectPdf license. Windows, Linux x64/ARM64, macOS on Apple Silicon, Docker; no wkhtmltox libraries or apt-get. Not affiliated with WkHtmlToPdf-DotNet. |
|
|
SelectPdf.Compat.DinkToPdf.Licensed
The DinkToPdf API (IConverter, SynchronizedConverter, HtmlToPdfDocument, GlobalSettings, ObjectSettings) on the licensed SelectPdf.Universal library: Chromium rendering with no page limit, instead of wkhtmltopdf. The same code as the free SelectPdf.Compat.DinkToPdf package, for applications with a SelectPdf license. Windows, Linux x64/ARM64, macOS on Apple Silicon, Docker; no libwkhtmltox files. Not affiliated with DinkToPdf. |
|
|
SelectPdf.Universal.Linux.Arm64
The SelectPdf PDF library for .NET on Linux ARM64 and Docker. This package contains no code: it installs SelectPdf.Universal (HTML to PDF and Word to PDF conversion, PDF creation and editing, redaction, digital signatures, PDF/A and PDF/UA) together with the Chromium engine package for linux-arm64. The engine is bundled, so Docker images need no apt-get. Requires glibc 2.30 or later. For Linux x64, use SelectPdf.Universal.Linux. |
|
|
SelectPdf.Universal.Linux
The SelectPdf PDF library for .NET on Linux x64 and Docker. This package contains no code: it installs SelectPdf.Universal (HTML to PDF and Word to PDF conversion, PDF creation and editing, redaction, digital signatures, PDF/A and PDF/UA) together with the Chromium engine package for linux-x64. The engine is bundled, so Docker images need no apt-get. Requires glibc 2.30 or later. For Linux ARM64, use SelectPdf.Universal.Linux.Arm64. |
GitHub repositories
This package is not used by any popular GitHub repositories.
