Getting started
Install
dotnet add package NetPdfKit
Lean install
Pick what you need. NetPdfKit is the full install. NetPdfKit.Core is the lean one, with no SkiaSharp, SVG, barcode or PDFium dependencies.
| Package | Adds | Pulls in |
|---|---|---|
NetPdfKit |
Everything below | Core + all add-ons |
NetPdfKit.Core |
Create, merge, split, encrypt, extract text and images | PDFsharp, PdfPig |
NetPdfKit.Svg |
Svg(), ImageSource.FromSvg |
Svg.Skia |
NetPdfKit.Barcodes |
QrCode(), Barcode(), BarcodeGenerator |
ZXing.Net |
NetPdfKit.Rendering |
RenderPage(), RenderAllPages() |
PDFtoImage (PDFium) |
# lean: just the core
dotnet add package NetPdfKit.Core
# then only what you use
dotnet add package NetPdfKit.Barcodes
Each add-on extends the core in the same namespaces, so your code needs no extra using. If you call QrCode() without NetPdfKit.Barcodes installed, it won't compile. Add the package and it will.
The package targets net8.0, net9.0, net10.0, and net11.0 and works on Windows, macOS, and Linux. Fonts come from your registered fonts (NetPdfFonts.Register), then the operating system's font directories, then a bundled Liberation Sans. So minimal Linux containers work without installing any font package. For Arial-like text on Linux, installing fonts-liberation is still fine but no longer needed.
Create your first PDF
The coordinate-based builder gives you precise control. Coordinates are PDF points (1/72 inch) measured from the top-left corner, and page indexes are 0-based everywhere.
using NetPdf;
PdfFile.Create()
.WithMetadata(m => m.Title("Report").Author("Me"))
.AddPage(page => page
.AddText("Hello, world", x: 50, y: 50, o => o.FontSize(24).Bold())
.AddText("Wrapped body text…", x: 50, y: 100, o => o.Wrap(400))
.AddImage("logo.png", x: 50, y: 200, width: 150)
.AddRectangle(50, 400, 200, 80, fill: System.Drawing.Color.LightGray)
.AddEllipse(300, 400, 100, 60, fill: System.Drawing.Color.LightBlue)
.AddRoundedRectangle(50, 500, 200, 60, cornerRadius: 8)
.AddWebLink(50, 50, 200, 24, "https://example.com/"))
.WithOutline(o => o
.AddBookmark("Introduction", 0))
.Save("report.pdf");
Text supports styling and layout options: Bold(), Italic(), Underline(), Strikethrough(), Align(TextAlignment.Center), Wrap(width), and LineSpacing(1.5).
Two ways to author documents
NetPdf has two authoring models — pick the one that fits:
- Coordinate drawing (
PdfFile.Create(), shown above) — you place every element at explicit x/y positions. Best for stamps, forms, and pixel-precise output. - Fluent layout (
Document.Create(...)) — content is measured and paginated automatically, with repeating headers/footers and page numbers. Best for reports and flowing documents. See Fluent layout.
Next steps
- Fluent layout — auto-paginated documents
- Reading PDFs — open and extract content
- Managing PDFs — merge, split, encrypt, and more