The Free C# PDF Library for .NET Developers

Generate professional PDFs entirely from C# — invoices, reports, contracts, and certificates — with a fluent, code-first API. Zero dependencies, no native binaries, MIT-licensed, with tables, images, bookmarks, vector graphics, barcodes, QR codes, and AES-256 encrypted output built in.

Built for generating invoices, reports, business documents, and more — straight from your application, with no design tool in the loop.

Latest NuGet version Latest on NuGet
NuGet download count NuGet Downloads
GitHub star count GitHub Stars
v1.5.1 .NET 10 Support

From C# code to a finished PDF

Describe the document with a fluent API — TerraPDF lays it out, paginates it, and writes the file. Write the code on the left; the page on the right is the actual PDF it produces, rendered by TerraPDF v1.5.1 — scannable QR code and barcode included.

PackingSlip.cs Full sample →
var brand = "#1A3C5E";
(string Item, string Sku, int Qty)[] lines =
[
    ("Wireless Mouse — Graphite",   "SKU-10231", 24),
    ("Mechanical Keyboard, 87-key", "SKU-10456", 12),
    ("USB-C Dock, Dual 4K",         "SKU-10877",  6),
    ("Laptop Stand, Aluminium",     "SKU-10920", 18),
];

Document.Create(doc =>
{
    doc.Page(page =>
    {
        page.Size(PageSize.A5);
        page.Margin(1.5, Unit.Centimetre);
        page.DefaultTextStyle(s => s.FontSize(10));

        page.Header().Column(col =>
        {
            col.Item().Row(row =>
            {
                row.RelativeItem().AlignMiddle()
                   .Text("TerraPDF Logistics").Bold().FontSize(13).FontColor(brand);
                row.AutoItem().AlignRight()
                   .Text("PACKING SLIP").Bold().FontSize(20).FontColor(brand);
            });
            col.Item().LineHorizontal(2, brand);
        });

        page.Content().PaddingTop(14).Column(col =>
        {
            col.Spacing(14);

            col.Item().Row(row =>
            {
                row.RelativeItem().Column(shipTo => { /* address block */ });
                row.AutoItem()   // vector QR code — new in v1.5
                   .QrCode("https://terrapdf.example/track/ORD-2026-1187", size: 88);
            });

            col.Item().Table(table =>
            {
                table.ColumnsDefinition(c =>
                {
                    c.RelativeColumn(5);  // Item
                    c.RelativeColumn(2);  // SKU
                    c.RelativeColumn(1);  // Qty
                });
                // brand header row + one shaded row per line item
            });

            col.Item().AlignCenter()  // vector Code128 — crisp at any zoom
               .Barcode("ORD-2026-1187", height: 46, showCaption: true);
        });

        page.Footer().AlignCenter().Text(t =>
        {
            t.Span("Page ");
            t.CurrentPageNumber();
            t.Span(" of ");
            t.TotalPages();
        });
    });
})
.PublishPdf("packing-slip.pdf");
The packing slip PDF generated by the code sample: a TerraPDF Logistics header, ship-to address with a QR tracking code, a shaded line-items table, and a Code128 barcode of the order number

What's new in TerraPDF v1.5.1

Now targeting .NET 8, 9, and 10 (LTS) — alongside the v1.5 line's vector-rendered Code128 barcodes and ISO/IEC 18004 QR codes, built from scratch with no raster image pipeline.

Code128 Barcodes

container.Barcode("SKU-00042") renders a Subset B Code128 barcode as vector-filled bars, with optional caption, custom colours, and a configurable quiet zone.

QR Codes

container.QrCode("https://...") generates a from-scratch ISO/IEC 18004 QR code — versions 1-40, all four error correction levels, with Reed-Solomon error correction.

🔎

Crisp at Any Zoom

Both render as vector-filled rectangles matching the existing Canvas rendering style — no raster images, and placeable inside any Column, Row, or Table cell.

Batch Rect Rendering

New PdfPage.AddFilledRects primitive emits one colour operator and a single trailing fill for symbols with thousands of modules, instead of a colour-set/fill pair per module.

Why TerraPDF?

Professional PDF generation in C# made simple. Designed for .NET developers who need code-first document creation, predictable layout, and full control.

Zero Dependencies

Pure C# implementation with no native binaries, no third-party runtime packages, and no licensing restrictions. Just add the NuGet package and you're ready.

🎨

Fluent API

Intuitive, composable builder pattern that makes PDF generation feel natural. Chain methods together to create complex layouts with minimal code.

📐

Full Layout Control

Columns, rows, tables, margins, padding, borders, backgrounds, and alignment. Everything you need for professional document layouts.

🖼️

Image Support

Embed PNG and JPEG images directly into your PDFs with proper sizing and positioning support.

📑

Automatic TOC

Generate a table of contents automatically from your headings (H1-H6) with clickable internal links and proper page numbering.

🔗

Hyperlinks & Bookmarks

Support for URI hyperlinks, internal document links, PDF bookmarks, and hierarchical outline navigation.

🔐

Document Security

AES-256 PDF encryption by default with user passwords, owner passwords, and fine-grained permission flags.

Barcodes & QR Codes

Vector-rendered Code128 barcodes and ISO/IEC 18004 QR codes, placeable anywhere an IContainer is exposed.

Everything You Need to Build Amazing PDFs

A focused PDF toolkit for C# apps: layout, styling, navigation, media, graphics, and security without a heavy runtime footprint.

Typography

🔤 Rich Text Styling Bold, italic, underline, strikethrough with full font control
📏 Size & Scale Precise font sizing and line-height control
🎨 Color & Formatting Per-span formatting with custom colors and styles

Layout

📐 Columns & Tables Flexible column, row, and table layouts
📐 Margins & Padding Full unit support: pt, mm, cm, inch
🖼️ Images PNG and JPEG embedding with positioning

Advanced

📑 Auto Table of Contents TOC generated from H1–H6 with clickable links
🔗 Links & Bookmarks URI hyperlinks, internal links, and bookmarks
📄 Headers & Footers Reusable headers, footers, and page numbers
🔐 PDF Encryption AES-256 protection by default with passwords and permissions
📈 Vector Canvas Shapes, paths, grids, charts, and diagrams
Barcodes & QR Codes Vector-rendered Code128 barcodes and ISO/IEC 18004 QR codes
À WinAnsi Text Windows-1252 and Latin-1 character coverage

Styling

🟢 Backgrounds & Borders Full, rounded, per-edge borders with fills
📐 Alignment Horizontal and vertical alignment controls
🏗️ Components Reusable components and conditional rendering

How TerraPDF Compares

Choose TerraPDF when you want an open-source .NET PDF library with code-first PDF generation, a small dependency footprint, and permissive licensing.

Library Best fit Licensing model Dependency footprint TerraPDF advantage
TerraPDF Code-first document generation for .NET apps MIT Pure C#, zero runtime dependencies Simple fluent API, tables, links, bookmarks, vector graphics, barcodes/QR codes, and AES-256 encryption in one package
QuestPDF Polished report and document layouts Community and commercial tiers Includes native rendering assets TerraPDF keeps the install smaller and the license story simpler for any project size
PDFsharp Lower-level PDF drawing, editing, merging, and splitting MIT .NET library with platform-specific build options TerraPDF focuses on higher-level document layout with tables, TOC, and fluent composition
iText 7 Enterprise PDF workflows, standards, editing, and add-ons AGPL or commercial Full-featured commercial-grade toolkit TerraPDF is lighter for straightforward generation when you do not need enterprise PDF tooling
DinkToPdf HTML-to-PDF conversion through wkhtmltopdf MIT Requires native wkhtmltopdf binaries TerraPDF avoids native renderer deployment and builds PDFs directly from C#

Build your next PDF with TerraPDF

Create reports, invoices, tables, images, bookmarks, and encrypted PDF documents in modern .NET apps with a small, MIT-licensed package.

dotnet add package TerraPDF View Documentation