Choosing a C# PDF Library: What Free Actually Costs

2026-11-26 05:41:00 Allen Yang
AI Summarize:
ChatGPT
ChatGPT ✓
Claude ✓
Grok ✓
Perplexity ✓
Quick
Quick
Concise overview
Highlights
Key takeaways
Detailed
Structured explanation
Brief
One sentence summary
Summarize |

Six C# PDF libraries tested on one real six-page IRS form: 149 checks across capability, round-trip preservation and licensing

A C# PDF library can pass a five-line "Hello, PDF" demo and still be the wrong dependency. The trouble starts later: a customer uploads a fillable form, your save operation drops its fields, or a license review reaches the AGPL clause after the code has shipped.

We tested PDFsharp, QuestPDF, iText, PdfPig, and Docnet against a real six-page IRS form, then put Spire.PDF for .NET through the same file. The comparison covers what each can do, what survives a save, and what the license permits in closed-source work. The fixture, harness, and scope are at the end, under How We Tested.

Which C# PDF Library Is Open Source, and What Does “Free” Mean?

Only two of the five open options can go into a closed-source product without buying a license: PdfPig (Apache-2.0) and Docnet (MIT). The other three are open in the sense that the source is published, not in the sense that a commercial application can use them for free. Spire.PDF is included as the commercial reference point.

Library Version tested License Closed-source product
PDFsharp 6.5.0 AGPL v3 or later + commercial Needs a commercial license
iText 9.8.0 AGPL v3 or later + commercial Needs a commercial license
QuestPDF 2026.9.2 Source-available, own terms Free only if you qualify
PdfPig 0.1.16 Apache-2.0 Unrestricted
Docnet 2.6.0 MIT Unrestricted
Spire.PDF for .NET 12.11.5 Commercial Paid license required

Four license positions across six C# PDF libraries: copyleft, source-available, permissive, and commercial

Where the free path stops

  • AGPL is not permissive. PDFsharp's pricing page says AGPL use requires your own project to be AGPL-licensed; closed-source or differently licensed products — internal, hosted, and SaaS included — need a commercial license. iText states the same for proprietary software and services. Both free paths assume you can relicense your application under AGPL, which most commercial products cannot.
  • QuestPDF is source-available, not open source. Its license says so outright, and Community use is free only below USD 1 million in annual gross revenue; public-sector bodies and publicly traded companies never qualify, whatever their revenue. Losing eligibility starts a 90-day transition.
  • The two unrestricted licenses belong to the two narrowest libraries. PdfPig cannot edit and save an existing PDF; Docnet cannot generate one. Each is good at its own job; neither replaces a general-purpose tool.
  • Free does not mean nothing to set up. iText's encryption needs an extra adapter package, PDFsharp needs a runtime license declaration and a font resolver, QuestPDF ships native binaries, and Spire.PDF needs a license key. Every library in the table asks for something before it produces a document.

Read together, the choice is less "open versus commercial" and more "which license a closed-source product ends up buying". Three of the five require one, and the two that do not are the two that cannot do the job alone.

This is technical context, not legal advice: the terms shipped with the version you deploy take precedence.

What Each Library Can Actually Do

A useful comparison separates reading, generating, modifying, and rendering — jobs that overlap less than their names suggest. In the table, a check mark means a tested API succeeded on our sample; it does not make the library a general-purpose editor, nor guarantee that structures survive. The next section answers that separate question.

Capability PDFsharp QuestPDF iText PdfPig Docnet Spire.PDF (commercial)
Generate text, graphics, and multiple pages ✓ ✓ ✓ ✓ (basic) ✗ ✓
Open an existing PDF ✓ ✓ ✓ ✓ ✓ ✓
Read page count and dimensions ✓ ✗ ✓ ✓ ✓ ✓
Extract text ✗ ✗ ✓ ✓ ✓ ✓
Extract embedded images ✗ ✗ ✓ (XObject level) ✓ ✗ ✓
Merge documents ✓ ✓ ✓ ✗ ✓ ✓
Split or select pages ✓ ✓ ✓ ✓ ✓ ✓
Append content to an existing page ✓ ✓ ✓ ✗ ✗ ✓
Read form fields ✓ ✗ ✓ △ ✗ ✓
Fill an AcroForm ✓ ✗ ✓ ✗ ✗ ✓
Flatten form fields into page content ✗* ✗ ✓ ✗ ✗ ✓
Add an annotation ✓ ✗ ✓ ✗ ✗ ✓
Read metadata ✓ ✗ ✓ ✓ (limited) ✗ ✓
Write metadata ✓ ✓ ✓ ✗ ✗ ✓
Password encryption ✓ ✓ ✓† ✗ ✗ ✓
Render pages to bitmaps ✗ ✓‡ ✗ ✗ ✓ ✓
HTML to PDF in the tested package ✗ ✗ ✗ ✗ ✗ ✓§
Save a complete existing document ✓ ✓ ✓ △ ✗ ✓

* On this W-9 with PDFsharp 6.5.0, Flatten() removed no fields and converted no appearances into page content; it set the read-only flag on the AcroForm's top-level field entry, a parent node here. See the flattening section.

† iText encryption needs itext.bouncy-castle-adapter or the FIPS adapter as an additional package.

‡ QuestPDF's tested GenerateImages renders documents built through its own layout API, not an arbitrary PDF loaded through DocumentOperation.

§ Spire.PDF is the commercial option; its column comes from an unlicensed evaluation build run through the same harness. HTML conversion calls into a headless Chrome installation or the Qt plugin folder.

PDFsharp: direct page and object control

PDFsharp suits drawing fixed layouts, appended content, page copying or removal, filling known fields, annotations, metadata, and security — operations kept close to the PDF object model. It has no text or image extraction and no rasterizer, plus two initialization requirements below.

QuestPDF: layout first, with more document operations than its reputation suggests

The fluent layout API suits reports and invoices that flow across pages, but "generation-only" no longer describes it. DocumentOperation, already in the 2024.12.0 package, loads, merges, selects pages, overlays, extends metadata, encrypts, decrypts, and linearizes — all tested. It still has no text or image extraction, no form filling or annotations, and no page-count or page-size query.

iText: the broadest open-source processing surface in this test

iText covers generation, page operations, text extraction, XObject-level images, form filling and flattening, annotations, metadata, and encryption — the widest open-source surface here. Its core package neither renders pages nor converts HTML.

PdfPig: inspect the document rather than rewrite it

PdfPig returns text with detailed positional and font information and extracts images, which fits parsing. Both triangles in the table come from one limitation: TryGetForm exposes the AcroForm and field types but no field-name or value accessors, returning one root field instead of 27. Its builder creates PDFs and rebuilds pages, but rebuilding drops fields and metadata.

Docnet: PDFium for reading, rasterizing, and page assembly

Docnet wraps PDFium for page information, text, bitmaps, splitting, and merging. Split(bytes, 0, 2) returns one byte array holding three pages; the third argument is the ending page index. It does not generate, append, or handle forms: in the split test the 27 AcroForm entries became zero, so treat it as a reader, not a form editor.

Spire.PDF for .NET: one document model instead of five

Spire.PDF is the only option built as a single document API rather than a specialist. Creation, extraction, form editing, annotation, security, and rasterization share one object model, so a workflow that starts with a generated report and ends with a flattened, encrypted PDF never changes library in between. That is what the unbroken column in the table represents. The cost is a license.

What Survives a Round Trip

We opened the W-9 with each library, saved it without edits, and inspected the result independently. A correct preview is only part of preservation.

Library Pages Form entries Page-one widgets Metadata Text Raster pixel difference File size
Original 6 27 23 ✓ — — 140,815 B
PDFsharp 6 27 23 ✓ ✓ 0.000% 225,616 B
QuestPDF 6 27 23 ✓ ✓ 0.000% 129,823 B
iText 6 27 23 ✓ ✓ 0.000% 131,041 B
PdfPig, rebuilt page by page 6 0 23 ✗ ✓ 0.000% 80,159 B
Docnet No general whole-document save; see its split/merge limitations above
Spire.PDF (evaluation) 6 27 23 ✓ ✓ 0.252%† 147,497 B

"Raster pixel difference" compares page one at 100 dpi in RGB with default antialiasing, counting a pixel when a channel differs by more than 8/255. 0.000% means identical visual output for that page in that renderer, not preservation of objects, signatures, JavaScript, attachments, bookmarks, or layers; the structural columns answer that.

† Spire.PDF was an unlicensed evaluation build. The 0.252% is the Evaluation Warning banner it adds to each page; with that strip excluded the difference is 0.000%, and pages, fields, widgets, metadata, and text all survive.

PDFsharp, QuestPDF, iText, and Spire.PDF passed every structural check and the visual comparison — evidence against the assumption that a save from an open-source, source-available, or commercial .NET library necessarily damages the original.

PdfPig shows why visual inspection is insufficient. Its rebuilt file was 0.000% different on page one, kept 23 widget dictionaries, and lost every AcroForm entry and the metadata. A reader sees the same tax form; an application reading its fields sees nothing usable. The smaller file is a consequence of the rebuild, not better compression.

PdfPig's rebuilt W-9 looks visually identical, but its usable form-field structure is gone

PDFsharp's output grew about 60% here; that belongs in the record, but one form cannot rank libraries by output efficiency.

Form Flattening: What Happens to Interactive Fields

Flattening should turn field appearances into ordinary page content, leaving values visible without editable fields. An API named Flatten does not guarantee that.

We filled the first W-9 name field with "ACME LLC", invoked each flattening API, and checked terminal fields with an /FT entry, annotations, page-only text extraction, and rendering. Because an extractor can read a value through a widget's appearance stream without it becoming page content, page-only extraction is an extra check. This covers AcroForm fields only, not comments, highlights, stamps, or layers.

Library and call Terminal fields afterward Page-one annotations Value appears in page-only text extraction Visual difference from the same library's filled, unflattened file
iText: form.FlattenFields() 0 0 Yes 0.000%
Spire.PDF: form.Flatten() 0 0 Yes 0.000% after excluding the evaluation banner
PDFsharp 6.5.0: doc.Flatten() 27 23 No 0.000%
QuestPDF No form-flattening API — — —
PdfPig Reads forms, cannot fill or flatten — — —
Docnet No form API — — —

iText and Spire.PDF both performed the expected operation: their 23 page-one annotations were form widgets and disappeared with the fields, and page-only extraction then returned the value that the filled-but-unflattened files did not expose. Because the value was already visible through the widget, both versions looked identical.

For Spire.PDF, pypdf still reported four parent nodes such as topmostSubform[0]. They carry no /FT and are not fillable, so verification scripts should count terminal fields rather than every form dictionary.

PDFsharp 6.5.0 kept all 27 terminal fields and 23 widgets, did not return the value in page-only text, and was visually identical to the filled, unflattened file. Its implementation sets ReadOnly on each entry of the AcroForm's top-level /Fields array; this form has one top-level parent holding all 27 fields, so the flag landed there and every leaf stayed fillable. Forms listing fields at the top level would behave differently, which is why this finding is version- and fixture-specific.

In the upstream master branch as of November 2026, the method has been replaced with a throw: "This function does nothing useful and was removed." Version 6.5.0 is the one tested here. If flattening is a delivery requirement, inspect terminal fields and page-only text in the saved file. For a working implementation, see how to flatten PDF form fields in C#.

Setup Requirements: Licensing, Dependencies, and Fonts

The first runtime error usually comes from licensing or a native dependency rather than document code. Each library below asks for something before it will produce a document.

PDFsharp: declare the license before constructing a document

With PDFsharp 6.5.0, new PdfDocument() threw PdfSharpLicenseException before any document work when no license had been declared. Choose one path at startup:

// AGPL path: use this only if your project complies with the AGPL.
PdfSharp.PdfSharpLicense.SetAgplLicense();

// Commercial path: pass the license key issued with your purchase.
// PdfSharp.PdfSharpLicense.LoadLicense("<your-license-key>");

SetAgplLicense() is a license choice, not a way around a commercial requirement; gate it behind explicit configuration.

PDFsharp Core: configure a font resolver before creating a font

After declaring the license, creating an Arial XFont in the Core build produced:

InvalidOperationException: No appropriate font found for family name 'Arial'.
Implement IFontResolver and assign to 'GlobalFontSettings.FontResolver'.

On Windows, the tested shortcut is:

using PdfSharp.Fonts;

// Run once, before any XFont is created or font settings are queried.
GlobalFontSettings.UseWindowsFontsUnderWindows = true;

var font = new PdfSharp.Drawing.XFont("Arial", 12);

The property can be set once, and only before the first XFont. Linux and containers need IFontResolver plus redistributable fonts — untested here.

QuestPDF: set the license type that matches your eligibility

QuestPDF threw when generation ran without QuestPDF.Settings.License. After setting an applicable type, the same test passed:

using QuestPDF.Infrastructure;

// Community is valid only when your use meets the current eligibility terms.
QuestPDF.Settings.License = LicenseType.Community;

// For an organization with the corresponding paid license, use:
// QuestPDF.Settings.License = LicenseType.Professional;
// QuestPDF.Settings.License = LicenseType.Enterprise;

The enum validates neither revenue, public-sector status, nor ownership; choose the value from your actual license.

iText: add the cryptography adapter before encrypting

The core itext7 package handled the other operations, but password encryption failed until a Bouncy Castle adapter was installed:

dotnet add package itext.bouncy-castle-adapter --version 9.8.1.1

The test then passed with AES-128 through WriterProperties.SetStandardEncryption(...). The adapter has its own version line: these tests used itext7 9.8.0 with itext.bouncy-castle-adapter 9.8.1.1, and the two have to resolve together.

Spire.PDF: license key, same build

The evaluation and licensed builds are the same assembly. The evaluation copy used in these tests needed no key and stamps each page; with a purchased license, one call registers it at startup:

// With a license key, register it once before creating documents.
Spire.Pdf.License.LicenseProvider.SetLicenseKey("<your-license-key>");

Where a Gap Turns Into Work

A gap becomes a cost only when your workflow needs that operation. The real question is what else you must install, verify, and maintain.

Text and image extraction. PdfPig is the specialist when word positions and font details matter; Docnet pairs extraction with rasterization; iText keeps extraction beside editing. None of these replaces OCR for scanned documents. Spire.PDF returns both from one package: extracting PDF text and extracting embedded images.

Rendering uploaded pages. Docnet gives PDFium bitmaps for arbitrary input. QuestPDF's image generation applies to its own layout, so it does not remove the need for a renderer. PDFsharp and iText need another component. Spire.PDF renders pages itself (converting PDF pages to images).

Form workflows. PDFsharp fills known fields but did not flatten this sample; iText handles both; QuestPDF, PdfPig, and Docnet need a separate form-capable component. Spire.PDF fills and flattens through the same API (filling PDF form fields). Check appearance streams, fonts, and field hierarchies on your own forms.

HTML input. None of the five open-source or source-available packages converts HTML to PDF; QuestPDF.HTML and pdfHTML are separate packages. Spire.PDF converts it through a headless Chrome instance or the Qt plugin.

A two-library design is often reasonable — QuestPDF plus PdfPig, or PDFsharp plus Docnet — and the work is the boundary: shared fixtures, field checks, coordinated upgrades.

Maintenance and adoption

Cost of ownership also includes the state of the project you are depending on. These figures were collected in November 2026.

Library Last commit Latest release Open issues and PRs NuGet downloads
PDFsharp Oct 2026 6.5.0 (7.0 in preview) 139 87M
QuestPDF Nov 2026 2026.9.2 37 47M
iText Nov 2026 9.8.1.1 (9.8.0 tested) 14 58M
PdfPig Nov 2026 0.1.16, still pre-1.0 34 49M
Docnet May 2024 2.6.0, September 2023 — 7.5M

Docnet is the outlier: no commit since May 2024, last stable package from September 2023, and roughly a sixth of the downloads. A PDFium wrapper that still works is not a liability today, but nothing recent sits behind it.

PDFsharp carries the largest open queue — 139 against 14 for iText — worth reading alongside its 6.5 licensing change and the removed Flatten(). PdfPig is still 0.1.x after years in production, which matches its API: solid reading primitives, no committed editing model.

The commercial option has no public tracker or commit history, so you cannot audit its pace the way you can a repository; you trade that transparency for a support contract.

Picking the Right Tool for the Job

There is no single "best PDF library" for every project. There is, however, a clear first candidate for each requirement:

Requirement First candidate Why
Drawing fixed layouts and manipulating PDF pages or objects PDFsharp Direct drawing and page/object control, with form filling and security
Reports, invoices, and flowing document layouts QuestPDF Fluent layout API, plus useful merge, overlay, and encryption operations
Broad open-source processing, including extraction, forms, and annotations iText The widest tested open-source API surface; check AGPL fit first
Text analysis with positional and font information PdfPig Detailed inspection APIs under Apache-2.0
Rendering uploaded PDFs, extracting text, and assembling page ranges Docnet PDFium-backed reading and bitmap output under MIT
Several operation types in one supported commercial component Spire.PDF for .NET Generation, extraction, editing, forms, security, and rendering in one API

Use this as a shortlist, not a ranking: license compatibility can eliminate the apparent winner before any API comparison begins. Then test representative files — an ordinary document, one with your hardest fonts or layout, and one containing every interactive structure you must retain.

Check more than whether a viewer opens the output: page counts, text, metadata, terminal fields, widgets, and rendered pages. Add signatures, attachments, bookmarks, or layers when your inputs use them; that harness outlives these versions.

When One Commercial Component Makes Sense

The commercial case is about when Spire.PDF for .NET earns its license. Consolidation removes integration work: no coordinating a renderer, a form library, and a cryptography adapter, and one licensing relationship to own. Those advantages matter most when the requirement list is broad; a focused open-source or source-available library remains the better economic choice for single-purpose work.

The sample below comes from the same build used in the tests. It shows the kind of page the API produces without extra tooling: a full-width header band, a table with alternating rows, and a right-aligned totals block, all drawn through PdfGraphics on an A4 canvas.

An invoice generated with Spire.PDF, showing a navy header band, a five-row line-item table, a PAID status block and a right-aligned totals column

The workflow behind the flattening result earlier in this article is short:

using Spire.Pdf;
using Spire.Pdf.Interactive.Forms;

using var document = new PdfDocument();
document.LoadFromFile("w9.pdf");

var form = PdfForm.Create(document);
var field = (PdfTextField)form.GetField("topmostSubform[0].Page1[0].f1_01[0]");
field.Text = "ACME LLC";

form.Flatten();
document.SaveToFile("w9-flat.pdf");

Deployment costs deserve equal prominence, and they are spread evenly: iText's encryption adapter, PDFsharp's font resolver, the native binaries in QuestPDF and Docnet, and here the HTML conversion engine — a headless Chrome installation or the Qt plugin. The scope limits under How We Tested apply here too.

If the consolidated route fits, download the Spire.PDF for .NET evaluation and run it against the same fixtures, including one form that must remain fillable and another that must be flattened.

Frequently Asked Questions

Is QuestPDF open source?

No. QuestPDF is source-available, not OSI-approved open source. Community is free for qualifying users, including small businesses below USD 1 million revenue; public-sector entities outside the academic exception and publicly traded companies never qualify.

Can I use PDFsharp or iText in commercial software?

Technically yes, but in a closed-source product it usually means buying a commercial license. PDFsharp's pricing page says AGPL use requires your own project to be AGPL-licensed too, and lists internal, hosted, and SaaS applications under the commercial license. If you cannot release your application under AGPL, price the commercial license before choosing.

Which C# PDF library can flatten form fields?

iText flattened the W-9 with form.FlattenFields(), and Spire.PDF did so with form.Flatten() in the evaluation build (see how to flatten a PDF form in C#). PDFsharp 6.5.0's Flatten() did not flatten this sample, and QuestPDF exposes no form-flattening API. Verify terminal fields and page content in your own output rather than trusting an API name.

Do I need a second library to render PDF pages?

It depends on the first choice. Docnet renders pages through PDFium and Spire.PDF includes page-to-image rendering. PDFsharp and iText need a separate renderer; QuestPDF's GenerateImages renders its own layout output, not arbitrary PDFs.

How We Tested

The fixture is the IRS's public Form W-9, Rev. March 2024: six pages, 27 AcroForm entries, and 23 /Widget annotations on page one, with embedded fonts and vector graphics. A generated blank page would miss the interesting failure — a library can reproduce every visible character while returning a file that no longer accepts input — so we compared both the rendered page and the PDF structure after each round trip.

The 140,815-byte source file has this SHA-256 checksum, so another team can verify that it is testing the same fixture:

2d420cbb4123dcf1fb82595b2359cfbb5d81f00b9df9d359fcc7af361d093f53

Tests ran on .NET 10.0.303, Windows 11 x64: six libraries, 149 checks — 113 passes, 36 confirmed API gaps, none failed. Each gap was confirmed by scanning the assembly's public API and then running the operation. pypdf 6.21.4 inspected structure and PyMuPDF 2.1 rendered output; neither depends on the library under test.

Generation used a basic three-page document rather than a typographic stress test. The W-9 holds no embedded images, so image extraction ran on a separate one-page fixture with a 64×64 PNG. Out of scope: performance, memory, concurrency, files over 100 pages, signatures, encrypted input, PDF/A, and non-Windows deployment.

Disclosure: Spire.PDF for .NET is E-iceblue's commercial product, and E-iceblue ran every test with the same harness and input file. Version 12.11.5 was an evaluation copy that stamps each page; where that affects a measurement, the figure is reported separately.

See Also