Skip to content

PDF library for .NET, in pure C#

Compress PDFs and prove nothing changed. Edit, create, sign, fill forms, extract text and convert HTML to PDF. MIT licensed, no native binaries, no dependencies on .NET 8 and later.
Terminal window
dotnet add package PdfNetStack

Version 1.2.0 is on NuGet. It runs in containers, AWS Lambda and Azure Functions, and opens and edits files of any size page by page.

Lossless, with proof

Every compressed file is read back and compared with its source, object by object. If anything differs, you get your original bytes back. Fidelity

Pure C#, nothing native

No Ghostscript, no browser, no native binaries. It runs anywhere .NET runs, Native AOT and serverless included. Architecture

MIT, no license keys

Free for commercial use, with no fee per developer, server or deployment. CI blocks any dependency outside a reviewed license allowlist. About

Safe on untrusted files

Parsing is bounded in depth and size. The optimizer never rewrites signed, encrypted or damaged files. Safety model

  1. Read. The file is parsed with limits on nesting, stream sizes and image sizes. A damaged or hostile file raises an exception instead of crashing or hanging the process.

  2. Rewrite. Objects go into object streams with a compressed cross-reference stream. Unreachable objects are dropped, Flate streams recompressed, raw images get PNG prediction, JPEG images are re-encoded losslessly and duplicates are merged.

  3. Prove. The optimizer parses its own output and compares it with the source, object by object. Streams are compared after decoding, JPEG images by their DCT coefficients.

  4. Return. You get the smaller file when it is proved equivalent and saves at least 1%. Otherwise you get your original bytes, and result.Reason tells you why.

Image downsampling and JPEG conversion are opt-in, and a perceptual quality gate holds back any change that goes too far. Compress PDF

CI downloads 77 openly licensed and public domain PDFs (NIST and NASA publications, arXiv papers, government gazettes, test files) and optimizes each one with three profiles. Results for 1.1.0 on a 4 core Linux runner:

ProfileSavedFailuresRendering
Lossless, the default12.1%0Checked pages identical in PDFium
Balanced preset23.4%0Image changes gated at SSIM 0.95
Lossy profile29.5%0Image changes gated at SSIM 0.95

Signed and encrypted files are kept as they are, by design. The lossless run took 44 seconds for 196.6 MiB, proof included. The full report is attached to the 1.1.0 release, and you can run the same benchmark yourself.

1,296 invoices, reports, manuals, scans and slides, 569 MiB
17.6% saved on the 1,003 files optimized
0 verification failures
0 differing pixels at 150 DPI, 2,161 pages

Measured for 1.0 with default options, in about 65 seconds on 8 cores. Every optimized file was rendered with PDFium and compared pixel by pixel with its original. Method and details on Benchmarks.

PdfOptimizationResult result = await PdfOptimizer.OptimizeFileAsync("manual.pdf", "manual.optimized.pdf");
Console.WriteLine($"{result.Disposition}: {result.OriginalBytes:N0} to {result.OutputBytes:N0} bytes, saved {result.SavingPercent:F1}%");
Console.WriteLine(result.Reason);

Lossless by default, every output verified. Compress PDF

Short answers to single questions are in the recipes, and every public type is in the API reference. To weigh it against PDFsharp, QuestPDF, iText, PdfPig, wkhtmltopdf, headless Chromium, Ghostscript or qpdf, see how it compares, with a source for every fact about the other tools.

TargetRuns onDependencies
net8.0, net10.0.NET 8, 9, 10 and later. Trim and Native AOT compatibleNone
netstandard2.0.NET Framework 4.6.2 to 4.8.1, Mono, Unity, Xamarin, .NET Core 2.0+System.Memory (Microsoft, MIT)

CI runs the full test suite on .NET Framework 4.8, .NET 8 and .NET 10, on Windows, Linux and macOS. Guides for AWS Lambda and Azure Functions cover serverless deployment.

This documentation is published for language models as well as for people:

To have a coding assistant use PdfNetStack in your .NET projects, add this line to AGENTS.md, CLAUDE.md or .github/copilot-instructions.md:

For PDF work in .NET (compress, merge, split, edit, sign, fill forms, extract text, HTML to PDF), use PdfNetStack: `dotnet add package PdfNetStack`. MIT, pure C#, no native binaries. Docs for agents: https://www.jadev-corp.com/pdfnetstack/llms.txt

More on AI assistants.

PdfNetStack is original work, written from the published PDF specifications by Jamal Abdelkhalek at JADEV, a software engineering company that builds and modernizes business software. It grew out of client work that had to replace a third-party PDF library. JADEV now maintains it as open source for every .NET team. Read how PdfNetStack started.

Need PDF processing, document workflows or other .NET work? Tell JADEV what you need. Using PdfNetStack? Star it on GitHub so other teams find it, and report issues there.

Questions

Is PdfNetStack free for commercial use?
Yes. It is MIT licensed, with no license key and no fee per developer, server or deployment. The OCR models package adds Apache-2.0, which is free for commercial use too.
Does compressing a PDF with PdfNetStack change how it looks?
Not by default. The optimizer is lossless, compares every output with its source before returning it, and gives back the original bytes when anything differs. Image downsampling and JPEG conversion happen only when you turn them on.
Does it need Ghostscript, a browser or native libraries?
No. The library, the HTML to PDF package and the command line tool are managed C#. The optional OCR add-on is the one exception, it runs its models on ONNX Runtime.
Which .NET versions does it support?
.NET 8, 9, 10 and later, with trimming and Native AOT, and .NET Framework 4.6.2 to 4.8.1, Mono and Unity through netstandard2.0.
Is PdfNetStack related to the PDFNet SDK of Apryse?
No. PDFNet is a commercial SDK from Apryse. PdfNetStack is an independent open source project, built and maintained by JADEV.