PdfPecker.Fluent
1.20.0
dotnet add package PdfPecker.Fluent --version 1.20.0
NuGet\Install-Package PdfPecker.Fluent -Version 1.20.0
<PackageReference Include="PdfPecker.Fluent" Version="1.20.0" />
<PackageVersion Include="PdfPecker.Fluent" Version="1.20.0" />
<PackageReference Include="PdfPecker.Fluent" />
paket add PdfPecker.Fluent --version 1.20.0
#r "nuget: PdfPecker.Fluent, 1.20.0"
#:package PdfPecker.Fluent@1.20.0
#addin nuget:?package=PdfPecker.Fluent&version=1.20.0
#tool nuget:?package=PdfPecker.Fluent&version=1.20.0
PdfPecker.Fluent
A fluent C# API for building PDFs with PdfPecker. You describe pages, headers, footers, columns, rows, tables, text, images and barcodes in code, in the style of QuestPDF. PdfPecker.Fluent turns that into compact HTML and CSS and renders it with PdfPecker, so it needs no browser, no native binaries and no package other than PdfPecker.
dotnet add package PdfPecker.Fluent
PdfPecker.Fluent is released together with PdfPecker and always has the same version, and it depends on the PdfPecker release of that version.
using PdfPecker.Fluent;
Document.Create(container =>
{
container.Page(page =>
{
page.Size(PageSizes.A4);
page.Margin(2, Unit.Centimetre);
page.DefaultTextStyle(x => x.FontSize(11));
page.Header().Text("Hello PdfPecker").FontSize(20).Bold().FontColor(Colors.Blue.Darken2);
page.Content().PaddingVertical(1, Unit.Centimetre).Column(column =>
{
column.Spacing(10);
column.Item().Text("A paragraph of text.");
column.Item().Image(File.ReadAllBytes("logo.png")).FitWidth();
});
page.Footer().AlignCenter().Text(x =>
{
x.Span("Page ");
x.CurrentPageNumber();
x.Span(" of ");
x.TotalPages();
});
});
})
.GeneratePdf("hello.pdf");
Features
- Layout:
Column,Row(relative, constant and auto items),Table(constant and relative columns, row and column spans, explicit placement, header and footer rows that repeat on every page), padding, borders, corner radius, background, width and height with minimum and maximum, alignment, page breaks,PreventPageBreak,ShowIfand right-to-left content. - More layout:
Layers(watermarks under and stamps over content),Inlined(items that wrap like words, such as tags),MultiColumn(newspaper columns),EnsureSpace(keeps a heading off the bottom of a page),Unconstrained,ZIndex,AspectRatio,Shadow, rounded single corners,Shrink,Placeholder,DebugAreaandLazy. - Repeating and lists:
Decoration(content with a part before and after it that repeat on every page it crosses) andList(bulleted, numbered or custom-marker lists, tagged as lists in PDF/UA). - Transforms:
Rotate,RotateLeft,RotateRight,Scale,ScaleHorizontal,ScaleVertical,FlipHorizontal,FlipVertical,FlipOver,TranslateXandTranslateY. - Text: spans with font family, size, weight, colour, background, italic, underline, strikethrough (solid, double,
wavy, dotted or dashed, in their own colour and thickness), line height, letter and word spacing, superscript and
subscript; OpenType features (
EnableFontFeature,DisableFontFeature); justified text,ClampLineswith an ellipsis, a first-line indent andParagraphSpacing; small slots inside the text for icons and badges (text.Element()); headings, which become PDF bookmarks and tags; links and links to named sections, and the page a section starts on (BeginPageNumberOfSection). - Pages: size, margins, page colour, a header and footer on every page, and
CurrentPageNumber/TotalPagesin them. SeveralPagecalls give page sets with their own size and margins. - Images and graphics: PNG, JPEG, WebP, BMP, TIFF and GIF images, SVG, solid, dashed and dotted lines, and QR, EPC payment QR, Code 128 and EAN-13 barcodes.
- Accessibility:
SemanticSection,SemanticArticle,SemanticHeader1to6,SemanticList,SemanticBlockQuotation,SemanticCaption,SemanticImage,SemanticIgnoreand the rest of QuestPDF's semantic calls write the HTML elements PdfPecker tags a PDF/UA document from. - Everything else in PdfPecker through the normal
PdfOptions: PDF/A, PDF/UA, signatures, encryption, watermarks, e-invoices (ZUGFeRD, Factur-X, XRechnung), attachments, fonts, viewer settings and page labels (which number the pages across everyPagecall) and linearized output for Fast Web View (a document with severalPagecalls is linearized once, after its page sets are merged).GeneratePdf(options)copies the options, so one options object can be shared. - An escape hatch:
container.Html("...")places raw HTML anywhere, anddocumentContainer.Css("...")adds stylesheet rules, for anything the fluent calls do not cover yet (form fields, floats, grid, footnotes). - Output:
GeneratePdf(bytes, file or stream),GeneratePdfAsync,GenerateImages(PNG, JPEG, WebP, TIFF) andGenerateHtml, which shows the HTML PdfPecker renders and opens in a browser.GeneratePdfAndShowandGenerateHtmlAndShowwrite a temporary file and open it, andPlaceholdersmakes up text, numbers, dates, colours and images (the same ones on every run) for trying out a layout. - .NET 8, 9 and 10, trimmable and Native AOT compatible, culture-independent output.
Safety
Text, links, colours and names you pass are encoded, so caller data never turns into markup: the fuzzer and the
hostile-input tests check that. Links must be absolute http, https or mailto addresses. Html and Css are
the exceptions: they insert trusted markup as it is, so never pass user input to them.
Invalid arguments throw ArgumentException (or ArgumentOutOfRangeException), an invalid document structure such
as an overlapping table cell throws InvalidOperationException, and PdfPecker's own limits throw
PdfPeckerException.
Coming from QuestPDF
Most QuestPDF code ports by changing the using lines: Document.Create, Page, Header, Content, Footer,
Column, Row, Table, Text, Span, Padding, Border, Background, Align*, Width, Height, Element,
Component and GeneratePdf have the same names. The differences:
PageSizes.A4.Landscapeis a property, not a method.Color.FromHexreads CSS order, so#rrggbbaaputs alpha last, where QuestPDF reads#aarrggbb.- Page numbers work in the header and footer, not in the content.
- In a table cell, put
BackgroundbeforePadding(.Background(...).Padding(...)) to fill the whole cell. - Each
Pagecall is converted on its own and the results are merged, so page numbers restart for each page set. PDF/A, PDF/UA and signatures need a singlePagecall. - Transforms change how content is drawn, not the space it takes:
Scale(2)draws twice as large from the top-left corner without making room.RotateLeftandRotateRightturn the layout itself (CSSwriting-mode), so give longer rotated content a height. MultiColumnbalances the columns unlessBalanceHeight(false), and has noSpacer.ClampLinesalways ends with an ellipsis.Lazybuilds its content straight away, since PdfPecker lays out the document in one pass.Decorationis a table underneath, so PDF/UA tags it as one, and its before and after parts repeat only where the page breaks between items of aColumncontent, not inside one item taller than a page.text.ElementwithBelowBaselinesits likeTop. Font features work with embedded fonts that have them.- Of the section page numbers, only
BeginPageNumberOfSectionis available. - Not available:
Dynamic,Canvas,StopPaging,ShowOnce,SkipOnce,RepeatContent,ScaleToFit,ExtendLastCellsToTableBottom,EndPageNumberOfSection,PageNumberWithinSection,TotalPagesWithinSectionand the Companion previewer. PdfPecker can now scale a box's content to fit it and give the first page a header of its own, soScaleToFit,ShowOnceandSkipOnceare the next calls planned.
Performance
The fluent layer costs well under a millisecond for a typical document: composing an invoice and writing its HTML takes about 0.8 ms, against about 1.2 ms for PdfPecker to render that HTML. Measured on a 4-core 2.1 GHz cloud VM with .NET 10 after a 12 s warm-up, medians:
| PdfPecker.Fluent | QuestPDF 2026.9.1 | |
|---|---|---|
| Invoice, 1 page | 3.5 ms | 14.0 ms |
| Invoice, 400 lines (14 pages) | 18.6 ms | 90.2 ms |
| Invoices per second, 4 cores | 947 | 249 |
| Package size | 0.2 MB + PdfPecker 11.8 MB | QuestPDF with native Skia binaries |
Both invoices come from the same code, call for call, in the
PdfPecker.Benchmarks repository. Run
bench/PdfPecker.Fluent.Benchmarks to see the fluent layer's own cost.
Source
PdfPecker.Fluent lives in the PdfPecker repository, next to the library:
src/PdfPecker.Fluent– the package.samples/PdfPecker.Fluent.Sample– writes each example as a PDF and as HTML. ItsExamples.csholds an invoice, a report, a product catalogue, a layout tour and a text tour, shared by the sample, the tests and the benchmarks.tests/PdfPecker.Fluent.Tests,fuzz/PdfPecker.Fluent.Fuzzandbench/PdfPecker.Fluent.*– seeTESTING.md.
License
MIT. PdfPecker, the one dependency, is MIT too, with the licenses of the fonts and data it bundles in its
THIRD-PARTY-NOTICES.md.
| 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. |
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
What changed in each release: https://pdfpecker.net/docs/changelog/