zPdfGenerator 0.1.4
See the version list below for details.
dotnet add package zPdfGenerator --version 0.1.4
NuGet\Install-Package zPdfGenerator -Version 0.1.4
<PackageReference Include="zPdfGenerator" Version="0.1.4" />
<PackageVersion Include="zPdfGenerator" Version="0.1.4" />
<PackageReference Include="zPdfGenerator" />
paket add zPdfGenerator --version 0.1.4
#r "nuget: zPdfGenerator, 0.1.4"
#:package zPdfGenerator@0.1.4
#addin nuget:?package=zPdfGenerator&version=0.1.4
#tool nuget:?package=zPdfGenerator&version=0.1.4
zPdfGenerator
A lightweight, fluent, and extensible PDF generation toolkit for .NET.
It provides two high-level generators:
๐ Available Generators
1๏ธโฃ FormPdfGenerator (AcroForm PDF filler)
Fills existing PDF form templates (AcroForms) with strongly-typed data models using a fluent builder and placeholder system.
2๏ธโฃ FluidHtmlPdfGenerator (HTML โ PDF renderer)
Will generate PDF documents from Fluid HTML templates and a strongly typed model.
โจ Features
โ๏ธ Shared features (both generators)
- Fluent API with strongly-typed placeholders
- Automatic culture-aware formatting (dates, numbers, currencies)
- Based on .NET 6+
- Extensible design โ add custom placeholders easily
- Built-in logging via
ILogger<T> - Supports cancellation tokens
- Fully testable and mockable
๐ฆ Installation
dotnet add package zPdfGenerator
Required for FormPdfGenerator
dotnet add package itext
dotnet add package itext.forms
dotnet add package itext.bouncy-castle-adapter
Required for HtmlPdfGenerator
dotnet add package itext.html2pdf
dotnet add package FluidCore
๐ FormPdfGenerator
FormPdfGenerator fills PDF AcroForms using a fluent builder and placeholder mapping.
Example Model
public class CustomerInfo
{
public string Name { get; set; }
public DateTime? BirthDate { get; set; }
public decimal? Balance { get; set; }
public decimal? Total { get; set; }
public string Currency { get; set; }
}
Simple Example
var pdf = new FormPdfGenerator(logger);
byte[] bytes = pdf.GeneratePdf<CustomerInfo>(builder =>
{
builder
.UseTemplatePath("templates/Contract.pdf")
.UseCulture(new CultureInfo("es-ES"))
.SetData(customer)
.AddText("Name", c => c.Name)
.AddDate("BirthDate", c => c.BirthDate, "dd/MM/yyyy")
.AddNumeric("Balance", c => c.Balance, "N2")
.AddNumericAndText(
"TotalWithCurrency",
c => new NumericAndTextValue(c.Total, c.Currency))
.AddFormElementsToRemove("OptionalSignature");
});
File.WriteAllBytes("ContractCompleted.pdf", bytes);
๐ Examples of Use
๐ Example 1: Basic text fields
builder
.SetData(order)
.AddText("OrderNumber", o => o.OrderNumber)
.AddText("CustomerName", o => o.CustomerName)
.AddText("Notes", o => o.Comments);
๐ Example 2: Date formatting with culture
builder
.UseCulture(new CultureInfo("es-ES"))
.AddDate("IssueDate", o => o.CreatedAt, "dd MMMM yyyy")
.AddDate("ExpiryDate", o => o.ExpiresAt, "dd/MM/yyyy");
๐ Example 3: Numeric formatting
builder
.UseCulture(new CultureInfo("de-DE"))
.AddNumeric("Amount", o => o.Amount, "N2")
.AddNumeric("TaxRate", o => o.TaxRate, "P1");
๐ Example 4: Composite numeric + text placeholder
builder.AddNumericAndText(
"AmountCurrency",
o => new NumericAndTextValue(o.Total, o.CurrencyCode),
"N2"
);
๐ Example 5: Removing form fields dynamically
builder.AddFormElementsToRemove("DebugField", "UnusedField");
๐ Example 6: Full configuration
var pdfBytes = generator.GeneratePdf<Invoice>(builder =>
{
builder
.UseTemplatePath("templates/Invoice.pdf")
.UseLicenseFile("licenses/itextkey.json")
.UseCulture(new CultureInfo("en-US"))
.SetData(invoice)
.AddText("InvoiceNumber", i => i.Number)
.AddText("CustomerName", i => i.Customer.Name)
.AddText("Address", i => i.Customer.Address)
.AddDate("InvoiceDate", i => i.Date, "MMMM dd, yyyy")
.AddNumeric("Total", i => i.Total, "C2")
.AddNumericAndText(
"TotalInWords",
i => new NumericAndTextValue(i.Total, i.CurrencyCode))
.AddFormElementsToRemove("OptionalCommentField", "InternalNotes");
});
๐ง Placeholder System Overview
| Placeholder Type | Maps From | Output |
|---|---|---|
TextPlaceHolder<T> |
Func<T, string> |
Raw text |
NumericPlaceHolder<T> |
Func<T, decimal?> |
Formatted number |
DateTimePlaceHolder<T> |
Func<T, DateTime?> |
Formatted date |
NumericAndTextPlaceHolder<T> |
Func<T, NumericAndTextValue> |
Composite (e.g., "1,234.00 EUR") |
๐งช Unit Testing
Creating a template programmatically:
var form = PdfFormCreator.GetAcroForm(pdf, true);
new TextFormFieldBuilder(pdf, "Name")
.SetWidgetRectangle(new Rectangle(50, 750, 200, 20))
.CreateText();
Reading values:
var form = PdfAcroForm.GetAcroForm(pdf, false);
var fields = form.GetAllFormFields();
string name = fields["Name"].GetValueAsString();
๐ FluidHtmlPdfGenerator
The future HTML engine will render PDFs directly from a Fluid HTML templates.
Planned features
- Fluid support
- Strongly typed model binding
- Shared placeholder API
- Embedded assets (CSS, fonts, images)
- Page layout configuration (margins, headers, footers)
Planned example
var pdf = new FluidHtmlPdfGenerator(logger, new HtmlToPdfConverter());
byte[] output = pdf.GeneratePdf(model, builder =>
{
builder
.UseHtmlTemplate("templates/Invoice.html")
.AddText("CustomerName", m => m.Name)
.AddNumeric("Total", m => m.Total);
});
โ๏ธ Requirements
- .NET 6 or later
- iText 8
- BouncyCastle Adapter
- A fillable PDF AcroForm template (for FormPdfGenerator)
- A fillable Fluid HTML template and CSS (for FluidHtmlPdfGenerator)
๐ License
MIT License for this library.
โ iText itself is AGPL unless you have a commercial license.
๐ค Contributing
- Fork the repository
- Create a feature branch
- Add tests
- Submit a PR
๐ฌ Support
Open an issue if you need help with:
- Custom placeholders
- Checkbox, radio, dropdown binding
- HTML template rendering
- Multi-page PDF generation
- Export pipelines
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Fluid.Core (>= 2.31.0)
- itext (>= 9.4.0)
- itext.bouncy-castle-adapter (>= 9.4.0)
- itext.licensing.base (>= 4.2.4)
- itext.pdfhtml (>= 6.3.0)
- Microsoft.DotNet.PlatformAbstractions (>= 3.1.6)
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.2)
- Newtonsoft.Json (>= 13.0.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on zPdfGenerator:
| Package | Downloads |
|---|---|
|
zPdfGenerator.Charts
A library for building charts for Pdf reports with iText through a fluent API. |
GitHub repositories
This package is not used by any popular GitHub repositories.