NetPdfKit 0.4.0
See the version list below for details.
dotnet add package NetPdfKit --version 0.4.0
NuGet\Install-Package NetPdfKit -Version 0.4.0
<PackageReference Include="NetPdfKit" Version="0.4.0" />
<PackageVersion Include="NetPdfKit" Version="0.4.0" />
<PackageReference Include="NetPdfKit" />
paket add NetPdfKit --version 0.4.0
#r "nuget: NetPdfKit, 0.4.0"
#:package NetPdfKit@0.4.0
#addin nuget:?package=NetPdfKit&version=0.4.0
#tool nuget:?package=NetPdfKit&version=0.4.0
NetPdf
Create, view, and manage PDF files in .NET with one fluent API.
NetPdf wraps three battle-tested, permissively-licensed libraries behind a single coherent surface:
| Capability | Powered by | License |
|---|---|---|
| Create, merge, split, rotate, encrypt | PDFsharp | MIT |
| Text & image extraction | PdfPig | Apache-2.0 |
| Render pages to PNG | PDFtoImage (PDFium) | MIT |
Targets net8.0, net9.0, and net10.0. Works on Windows, macOS, and Linux.
Install
dotnet add package NetPdfKit
Create a PDF
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).
Lay out a document
The fluent layout API measures and paginates content automatically — no coordinates needed.
Headers and footers repeat on every page, and {number}/{total} resolve to page numbers.
using NetPdf.Fluent;
Document.Create(doc => doc
.Page(page => page
.Size(PageSizes.A4)
.Margin(50)
.Header(h => h.Text("ACME Quarterly Report"))
.Content(c => c
.Padding(10)
.Column(column =>
{
column.Spacing(8);
column.Item().Text("Body text wraps and flows across pages automatically.");
column.Item().Row(row =>
{
row.ConstantItem(120).Text("Label");
row.RelativeItem().Text("Value that takes the remaining width");
});
}))
.Footer(f => f.AlignCenter().PageNumber("Page {number} of {total}"))))
.Save("report.pdf");
Containers compose with chainable calls: Padding, Width/Height (plus min/max),
AlignCenter/AlignMiddle/…, AspectRatio, Extend, Shrink, Unconstrained, and Offset.
Custom IElement implementations plug in via .Element(...).
Read a PDF
using var doc = PdfFile.Open("report.pdf");
Console.WriteLine(doc.PageCount);
Console.WriteLine(doc.Metadata.Title);
string allText = doc.ExtractText();
string pageText = doc.ExtractText(0); // 0-based
var images = doc.GetImages(0); // PNG bytes
Manage PDFs
Manipulation methods never mutate the original — each returns a new PdfDocument.
PdfFile.Merge(["a.pdf", "b.pdf"], "merged.pdf");
using var doc = PdfFile.Open("merged.pdf");
doc.Split(pagesPerFile: 1, "out/"); // one file per page
using var subset = doc.ExtractPages(0, 2, 4);
using var trimmed = doc.DeletePages(1);
using var swapped = doc.ReorderPages(1, 0);
using var rotated = doc.RotatePage(0, Rotation.Clockwise90);
using var titled = doc.WithMetadata(m => m.Title("New title"));
// Watermarks / letterheads: stamp a page of one PDF onto another
using var stamp = PdfFile.Open("watermark.pdf");
using var stamped = doc.Overlay(stamp); // on top of the content
using var letter = doc.Underlay(stamp); // beneath the content
// File attachments
using var withCsv = doc.AttachFile("data.csv", File.ReadAllBytes("data.csv"));
var attachments = withCsv.GetAttachments(); // name + content
// XMP metadata (apply last — other manipulations regenerate it from the Info dictionary)
using var withXmp = doc.WithGeneratedXmpMetadata(); // derived from Title/Author/…
string? xmp = withXmp.GetXmpMetadata(); // raw packet XML
// Encryption (AES-256 by default; Rc4_128 available for legacy readers)
using var locked = doc.Protect(userPassword: "secret");
locked.Save("locked.pdf");
// Reopen protected files with a password — all manipulations still work:
using var opened = PdfFile.Open("locked.pdf", password: "secret");
using var unlocked = opened.Decrypt(); // remove encryption
View (render to image)
using var doc = PdfFile.Open("report.pdf");
byte[] png = doc.RenderPage(0, dpi: 150);
File.WriteAllBytes("page1.png", png);
var allPages = doc.RenderAllPages(dpi: 96);
Notes
- Page indexes are 0-based everywhere; coordinates are PDF points (1/72 inch) from the top-left corner.
- Fonts are resolved from the operating system's font directories on all platforms.
Protectuses AES-256 by default; passEncryptionAlgorithm.Rc4_128only if a legacy reader requires it.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- PdfPig (>= 0.1.9)
- PDFsharp (>= 6.1.1)
- PDFtoImage (>= 5.1.0)
-
net8.0
- PdfPig (>= 0.1.9)
- PDFsharp (>= 6.1.1)
- PDFtoImage (>= 5.1.0)
-
net9.0
- PdfPig (>= 0.1.9)
- PDFsharp (>= 6.1.1)
- PDFtoImage (>= 5.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.