zPdfGenerator 0.1.8

dotnet add package zPdfGenerator --version 0.1.8
                    
NuGet\Install-Package zPdfGenerator -Version 0.1.8
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="zPdfGenerator" Version="0.1.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="zPdfGenerator" Version="0.1.8" />
                    
Directory.Packages.props
<PackageReference Include="zPdfGenerator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add zPdfGenerator --version 0.1.8
                    
#r "nuget: zPdfGenerator, 0.1.8"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package zPdfGenerator@0.1.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=zPdfGenerator&version=0.1.8
                    
Install as a Cake Addin
#tool nuget:?package=zPdfGenerator&version=0.1.8
                    
Install as a Cake Tool

zPdfGenerator

A lightweight, fluent, and extensible PDF generation toolkit for .NET. It provides two high-level generators and an extensible post-processing pipeline for advanced PDF operations.


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)

Generates 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)
  • Extensible architecture with post-processing pipeline
  • 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 FluidHtmlPdfGenerator

dotnet add package itext.pdfhtml
dotnet add package FluidCore

Post-Processing Pipeline

zPdfGenerator supports a composable post-processing pipeline that operates on the generated PDF bytes. Each post-processor implements the following interface:

public interface IPostProcessor
{
    bool LastPostProcessor { get; }
    byte[] Process(byte[] pdfData, CancellationToken cancellationToken);
}

Post-processors can be chained and executed in order. A single post-processor can be marked as LastPostProcessor (typically the digital signature), which is always executed at the end.


Available Post-Processors

1. DocumentClassifierPostProcessor

Adds document classification information using PDF metadata only (no visual changes).

Use cases:

  • Allow users to see classification in Acrobat Reader (File → Properties)
  • Enable downstream systems (DLP, indexing, compliance) to detect sensitivity

Metadata written:

  • Subject (e.g. Classification: Confidential)
  • Keywords (e.g. classification=confidential)
  • Custom fields: Classification, SI_DATA

Using the builder API:

var pdfBytes = generator.GeneratePdf(model, builder =>
{
    builder
        .UseHtmlTemplate("templates/Invoice.html")
        .AddText("CustomerName", m => m.Name)
        .AddNumeric("Total", m => m.Total)

        // Post-processing
        .AddPostDocumentClassifier(
            ClassificationEnum.Internal,
            new Dictionary<string, string>
            {
                ["Department"] = "Finance",
                ["System"] = "ERP"
            });
});

Reserved keys such as Classification and SI_DATA cannot be overridden.


2. PasswordProtectPostProcessor

Encrypts the PDF using a user password and an owner (master) password.

Behavior:

  • The document cannot be opened without a password
  • User password allows reading
  • Owner password allows full control

Using the builder API:

var pdfBytes = generator.GeneratePdf(model, builder =>
{
    builder
        .UseHtmlTemplate("templates/Invoice.html")
        .AddText("CustomerName", m => m.Name)
        .AddNumeric("Total", m => m.Total)

        // Post-processing
        .AddPostPasswordProtect(
            masterPassword: "owner-secret",
            userPassword: "user-secret");
});

This post-processor must be executed before digital signing.


3. PfxDigitalSignaturePostProcessor

Applies a digital signature to the PDF using a PFX (PKCS#12) certificate.

Key points:

  • Must be the last post-processor in the pipeline
  • Uses append mode to preserve previous changes
  • Supports visible and invisible signatures

Using the builder API:

var signatureOptions = new PdfSignatureOptions(
    pfxPassword: "secret",
    fieldName: "Signature1",
    visible: false
);

var pdfBytes = generator.GeneratePdf(model, builder =>
{
    builder
        .UseHtmlTemplate("templates/Invoice.html")
        .AddText("CustomerName", m => m.Name)
        .AddNumeric("Total", m => m.Total)

        // Classification
        .AddPostDocumentClassifier(
            ClassificationEnum.Confidential,
            new Dictionary<string, string> { ["Department"] = "Finance" })

        // Digital signature (always last)
        .AddPostPfxDigitalSignature(pfxBytes, signatureOptions);
});

The resulting PDF can be validated in Acrobat Reader (Signature Panel).


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");
});

FluidHtmlPdfGenerator

Renders PDFs from Fluid HTML templates.

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

  • netstandard2.1 or higher
  • iText 9.x
  • BouncyCastle adapter
  • A fillable PDF AcroForm template (FormPdfGenerator)
  • A Fluid HTML template and CSS (FluidHtmlPdfGenerator)

License

MIT License for this library.

iText itself is AGPL unless you have a commercial license.


Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests
  4. Submit a PR

Support

Open an issue if you need help with:

  • Custom placeholders
  • HTML template rendering
  • Post-processing pipelines
  • Digital signatures
  • PDF security and compliance
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
0.1.8 32 1/9/2026
0.1.7 235 12/19/2025
0.1.6 304 12/18/2025
0.1.5 263 12/17/2025
0.1.4 231 12/15/2025
0.1.3 233 12/15/2025
0.1.2 232 12/15/2025
0.1.1 169 12/5/2025
0.1.0 179 12/5/2025