Most PDF libraries in .NET are wrappers. PDFium, MuPDF, Ghostscript — solid engines, but they ship native binaries you P/Invoke into. That buys you per-RID packages, Native AOT friction, the "works on my box, throws DllNotFoundException in the Alpine container" dance, and a deployment story that's never quite boring.
as the 2D canvas to turn the parsed page into pixels. SkiaSharp carries a native component.
So the rule of thumb:
- Parsing, text extraction, editing, optimizing → fully managed, ship no native code.
- Rasterizing a page to an image → add SkiaSharp.
SkiaSharp is a well-behaved, broadly-supported cross-platform dependency, so this is a very different proposition from bundling and P/Invoking a PDF engine yourself — but it's not nothing, and you should know exactly where the line is.
It's not just a renderer
Rendering is the flashy demo, but the managed core is the actual point. A few things that need only the core package (no SkiaSharp):
Extract text:
using var doc = PdfDocument.Load("input.pdf");
string text = doc.GetPage(0).ExtractText(doc);
Edit an existing document:
using PdfLibrary.Editing;
using var doc = PdfDocument.Load("input.pdf");
var edit = doc.Edit();
edit.Pages.RemoveAt(2); // delete the 3rd page
edit.Pages.Rotate(0, 90); // rotate the 1st page 90°
edit.Save("edited.pdf");
Optimize / shrink:
using PdfLibrary.Optimization;
using var doc = PdfDocument.Load("input.pdf");
using var output = File.Create("optimized.pdf");
PdfOptimizer.Optimize(doc, output); // lossless by default
Threading
PdfLibrary is built for the one-document-per-request model — the standard pattern for ASP.NET Core. Load a PdfDocument per request, render it on its own target, dispose both. Under that model it's thread-safe, and the process-wide caches (glyph paths, font resolution, ICC profiles) are synchronized. The one thing you must not do is share a single PdfDocument (or a SkiaSharpRenderTarget) across threads.
Links
- NuGet:
- Source (MIT): github.com/lxman/PdfLibrary
- Targets .NET 8, 9, and 10.
If you try it and something doesn't render the way you expect, open an issue with the PDF attached — edge cases in the wild are how this kind of library gets better.
SOCIAL SHARE CARD GENERATOR