NetPdfKit.Rendering
1.1.0
dotnet add package NetPdfKit.Rendering --version 1.1.0
NuGet\Install-Package NetPdfKit.Rendering -Version 1.1.0
<PackageReference Include="NetPdfKit.Rendering" Version="1.1.0" />
<PackageVersion Include="NetPdfKit.Rendering" Version="1.1.0" />
<PackageReference Include="NetPdfKit.Rendering" />
paket add NetPdfKit.Rendering --version 1.1.0
#r "nuget: NetPdfKit.Rendering, 1.1.0"
#:package NetPdfKit.Rendering@1.1.0
#addin nuget:?package=NetPdfKit.Rendering&version=1.1.0
#tool nuget:?package=NetPdfKit.Rendering&version=1.1.0
NetPdf
Create, view, and manage PDF files in .NET with one fluent API.
π Full documentation & API reference: https://edcsu.github.io/netpdf/
NetPdf wraps battle-tested, permissively-licensed libraries behind a single coherent surface. Install everything with NetPdfKit, or start from the lean NetPdfKit.Core and add only what you use (see Install):
| Capability | Package | Powered by | License |
|---|---|---|---|
| Create, merge, split, rotate, encrypt | NetPdfKit.Core |
PDFsharp | MIT |
| Text & image extraction | NetPdfKit.Core |
PdfPig | Apache-2.0 |
| Render pages to PNG | NetPdfKit.Rendering |
PDFtoImage (PDFium) | MIT |
| Barcodes & QR codes | NetPdfKit.Barcodes |
ZXing.Net | Apache-2.0 |
| SVG rasterization | NetPdfKit.Svg |
Svg.Skia (SkiaSharp) | MIT |
Targets net8.0, net9.0, net10.0, and net11.0. Works on Windows, macOS, and Linux.
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.
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(...).
Content flow is controlled per block: ShowEntire keeps a block on one page, EnsureSpace(pt)
requires a minimum height before starting, PageBreak() forces a new page, StopPaging
truncates to the current page, and ShowOnce/SkipOnce/ShowIf(bool)/Repeat(...) control
repeated slots. DefaultTextStyle(style) cascades text styling to everything inside.
Rich text mixes styles, hyperlinks, and paragraph settings inside one flowing block, and
List/Inlined/Decoration cover common structures:
content.Column(column =>
{
column.Item().Text(text =>
{
text.LineHeight(1.4);
text.Span("NetPdf ").Bold();
text.Span("builds rich paragraphs β ");
text.Hyperlink("learn more", "https://example.com");
text.Span(".");
});
column.Item().List(list =>
{
list.Ordered().Spacing(4);
list.Item().Text("First point");
list.Item().Text("Second point");
});
});
Tables have fixed column widths, cell spans, and header/footer rows that repeat on every page; a spanned cell never splits across a page break:
content.Table(table =>
{
table.ColumnsDefinition(columns =>
{
columns.ConstantColumn(120);
columns.RelativeColumn();
});
table.Header(header =>
{
header.Cell().Text("Name");
header.Cell().Text("Description");
});
table.Cell().Text("Item 1");
table.Cell().Text("First item");
table.Cell().Row(2).Column(1).RowSpan(2).Text("Spans two rows");
});
Visual styling and transforms chain onto any container: Background(color, cornerRadius),
Border(...), Shadow(...) (blur is approximated β PDF has no native blur), Rotate(degrees),
Scale(x, y), FlipHorizontal/FlipVertical/FlipOver, and ScaleToFit() which shrinks
content until it fits its slot. Layers accept a zIndex to control stacking order.
QR codes, barcodes, and SVG render through the same image pipeline, and Canvas exposes raw
drawing for charts and custom graphics. QrCode() and Barcode() need NetPdfKit.Barcodes,
and Svg() needs NetPdfKit.Svg (both are included in NetPdfKit):
content.Column(column =>
{
column.Item().Width(120).QrCode("https://example.com");
column.Item().Width(240).Barcode("NETPDF-12345", BarcodeFormat.Code128);
column.Item().Width(80).Svg("<svg β¦>β¦</svg>"); // rasterized at 2Γ by default
column.Item().Height(100).Canvas((canvas, size) =>
canvas.DrawLine(0, size.Height, size.Width, 0, Color.SteelBlue, 2));
});
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
Compliance & long tail
// Tagged PDF (accessibility) + PDF/A-2b
var bytes = Document.Create(doc => doc
.Page(page => page.Content(c => c.Column(col =>
{
col.Item().Heading(1).Text("Title");
col.Item().Paragraph().Text("Body text");
col.Item().Image(logoPng, altText: "Company logo");
}))))
.WithTagging() // structure tree: headings, paragraphs, figures with alt text
.AsPdfA() // sRGB output intent + pdfaid identification XMP
.ToBytes();
// Right-to-left layout with bidi reordering and Arabic shaping
Document.Create(doc => doc
.Page(page => page
.ContentFromRightToLeft()
.Content(c => c.Text("Ω
Ψ±ΨΨ¨Ψ§ Ψ¨Ψ§ΩΨΉΨ§ΩΩ
"))));
// β¦or per container: c.ContentFromRightToLeft().Row(β¦)
// Digital signature (detached PKCS#7) β always the LAST operation
using var doc2 = PdfFile.Open(bytes);
using var signed = doc2.Sign(certificate, new SignatureOptions { Reason = "Approved" });
var sigs = signed.GetSignatures(); // SignerSubject, IsIntact, CoversWholeDocument
// Linearization ("fast web view") β rewrites the file, so do it before XMP/signing
using var fast = doc2.Linearize();
// Layout debugging: outline any element, or all page slots, then render to PNG
Document.Create(doc => doc
.Page(page => page
.DebugOverlay() // outlines header/content/footer
.Content(c => c.Debug("body").Text("β¦"))));
Operation ordering: manipulations β Linearize() β WithXmpMetadata() / AsPdfA() β Sign() last. Linearizing flattens prior incremental updates; any rewrite after signing invalidates the signature.
View (render to image)
Needs NetPdfKit.Rendering (included in NetPdfKit).
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);
Live previewer
Preview documents in a desktop window that re-renders on every rebuild β ideal with dotnet watch.
dotnet tool install -g NetPdfKit.Previewer.App # installs the netpdf-previewer window
dotnet add package NetPdfKit.Previewer # adds ShowInPreviewer() to your project
The tool needs the .NET 8 runtime or newer, and ~/.dotnet/tools on your PATH (the .NET SDK usually sets that up). ShowInPreviewer() starts the tool from PATH.
using NetPdf.Fluent;
using NetPdf.Previewer;
Document.Create(doc => doc
.Page(page => page
.Content(c => c.Text("Hello, previewer!"))))
.ShowInPreviewer(); // instead of .Save()/.ToBytes() while designing
Run your app under dotnet watch run: ShowInPreviewer() launches the previewer window if it isn't already running (default port 12500) and pushes the fresh PDF to it after each rebuild. Generation exceptions appear in the window's error panel instead of killing the loop. The window offers continuous-scroll pages, a thumbnail sidebar, zoom / fit-to-width, and a Save PDF button.
Fonts
Fonts are looked up in this order: fonts you register, fonts installed on the machine, then a bundled Liberation Sans. So PDFs work even in a container with no fonts installed.
To use your own font, register it once at startup, before you build any PDF:
using NetPdf;
NetPdfFonts.RegisterFile("Brand Sans", "fonts/BrandSans-Regular.ttf");
NetPdfFonts.RegisterFile("Brand Sans", "fonts/BrandSans-Bold.ttf", bold: true);
Then use the family name in a text span, for example t.Span("Hello").FontFamily("Brand Sans").
Notes
- Page indexes are 0-based everywhere; coordinates are PDF points (1/72 inch) from the top-left corner.
- Fonts: your registered fonts (
NetPdfFonts.Register) first, then the operating system's fonts, then a bundled Liberation Sans (SIL OFL) as a last fallback. A container with no fonts still produces PDFs. Missing bold/italic faces fall back to the regular face. Protectuses AES-256 by default; passEncryptionAlgorithm.Rc4_128only if a legacy reader requires it.- Rendering Arabic requires a font with presentation-form glyphs (e.g. Arial, Noto Naskh Arabic, Amiri).
- Linearization writes simplified (structurally valid) hint tables; the practical benefit is first-page-first ordering.
- Signature verification checks integrity only; certificate trust chains are not evaluated.
Contributing & releasing
- CONTRIBUTING.md β build, test, and PR guidelines.
- RELEASING.md β how tagged releases publish to NuGet.
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. net11.0 is compatible. |
-
net10.0
- NetPdfKit.Core (>= 1.1.0)
- PDFtoImage (>= 5.1.0)
-
net11.0
- NetPdfKit.Core (>= 1.1.0)
- PDFtoImage (>= 5.1.0)
-
net8.0
- NetPdfKit.Core (>= 1.1.0)
- PDFtoImage (>= 5.1.0)
-
net9.0
- NetPdfKit.Core (>= 1.1.0)
- PDFtoImage (>= 5.1.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on NetPdfKit.Rendering:
| Package | Downloads |
|---|---|
|
NetPdfKit
Create, view, and manage PDF files with one fluent API. Full install: NetPdfKit.Core plus SVG, barcode and page-rendering add-ons. For a lean install use NetPdfKit.Core. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.0 | 0 | 11/21/2026 |