![]() |
VOOZH | about |
dotnet add package zPdfGenerator --version 0.2.0
NuGet\Install-Package zPdfGenerator -Version 0.2.0
<PackageReference Include="zPdfGenerator" Version="0.2.0" />
<PackageVersion Include="zPdfGenerator" Version="0.2.0" />Directory.Packages.props
<PackageReference Include="zPdfGenerator" />Project file
paket add zPdfGenerator --version 0.2.0
#r "nuget: zPdfGenerator, 0.2.0"
#:package zPdfGenerator@0.2.0
#addin nuget:?package=zPdfGenerator&version=0.2.0Install as a Cake Addin
#tool nuget:?package=zPdfGenerator&version=0.2.0Install as a Cake Tool
👁 License: MIT
👁 NuGet
👁 NuGet (pre)
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.
Fills existing PDF form templates (AcroForms) with strongly-typed data models using a fluent builder and placeholder system.
Generates PDF documents from Fluid HTML templates and a strongly typed model.
dotnet add package zPdfGenerator
zPdfGenerator depends on iText packages, which are dual-licensed (AGPL/commercial). Ensure your usage complies with iText's license terms.
dotnet add package itext
dotnet add package itext.forms
dotnet add package itext.bouncy-castle-adapter
dotnet add package itext.pdfhtml
dotnet add package FluidCore
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.
Adds document classification information using PDF metadata only (no visual changes).
Use cases:
Metadata written:
Classification: Confidential)classification=confidential)Classification, SI_DATAUsing 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.
Encrypts the PDF using a user password and an owner (master) password.
Behavior:
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.
Applies a digital signature to the PDF using a PFX (PKCS#12) certificate.
Key points:
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).
Fills PDF AcroForms using a fluent builder and placeholder mapping.
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; }
}
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");
});
Renders PDFs from Fluid HTML templates.
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);
});
You can control rendered HTML logging and restrict external resource loading (images, CSS, etc.) during HTML → PDF conversion.
var resourcePolicy = new HtmlResourceAccessPolicy()
.AllowSchemes("file", "https")
.AllowHosts("cdn.example.com");
byte[] output = pdf.GeneratePdf(model, builder =>
{
builder
.UseTemplatePath("templates/Invoice.html")
.UseRenderedHtmlLogging(false)
.UseRenderedHtmlLogMaxLength(2000)
.UseResourceAccessPolicy(resourcePolicy)
.AddText("CustomerName", m => m.Name)
.AddNumeric("Total", m => m.Total);
});
Notes:
LogRenderedHtml defaults to true (debug level). Disable it in production if templates contain sensitive data.SetResourceRetriever currently relies on an obsolete IResourceRetriever type, which can emit compiler warnings. This is expected with the current iText API.dotnet test tests/zPdfGenerator.Tests/zPdfGenerator.Tests.csproj
Generate coverage:
dotnet test tests/zPdfGenerator.Tests/zPdfGenerator.Tests.csproj --collect:"XPlat Code Coverage"
basePath and allowed schemes/hosts.UseCulture explicitly and avoid mixing cultures in templates.MIT License for this library.
iText itself is AGPL unless you have a commercial license.
Open an issue if you need help with:
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
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. |
This package is not used by any popular GitHub repositories.