TPDF 0.4.3
See the version list below for details.
dotnet add package TPDF --version 0.4.3
NuGet\Install-Package TPDF -Version 0.4.3
<PackageReference Include="TPDF" Version="0.4.3" />
<PackageVersion Include="TPDF" Version="0.4.3" />
<PackageReference Include="TPDF" />
paket add TPDF --version 0.4.3
#r "nuget: TPDF, 0.4.3"
#:package TPDF@0.4.3
#addin nuget:?package=TPDF&version=0.4.3
#tool nuget:?package=TPDF&version=0.4.3
TPDF
TPDF is a .NET package for Word/DOCX workflows:
- Convert DOCX to PDF with the packaged in-process TPDF/LibreOffice runtime.
- Render Word
MERGEFIELDmail-merge templates with the managedTPDF.MailMergeassembly. - Merge a template and convert it directly to PDF without asking the caller to save an intermediate DOCX.
The package currently targets Linux x64 and Windows x64.
Install
dotnet add package TPDF
The package carries the native Linux and Windows TPDF runtimes. Its transitive build target copies the native library and tpdf-runtime folder beside your app output.
Convert DOCX To PDF
using TPDF;
Tpdf.ConvertDocxToPdf("input.docx", "output.pdf");
You can also pass DOCX bytes. TPDF still creates a temporary DOCX internally because the native converter is path-based, but your application does not have to persist or manage that file.
byte[] docxBytes = File.ReadAllBytes("input.docx");
Tpdf.ConvertDocxToPdf(docxBytes, "output.pdf");
byte[] pdfBytes = Tpdf.ConvertDocxToPdf(docxBytes);
Mail Merge Only
Use TPDF.MailMerge when you want to render a Word mail-merge template to a DOCX.
using TPDF.MailMerge;
var data = new MailMergeData(
Fields: new Dictionary<string, MailMergeValue>(StringComparer.OrdinalIgnoreCase)
{
["OrderId"] = new MailMergeValue.Text("TPDF-ORDER-001"),
["CustomerName"] = new MailMergeValue.Text("Morten Gryning"),
["SalesPrice"] = new MailMergeValue.Text("249.900 kr.")
},
Regions: new Dictionary<string, IReadOnlyList<IReadOnlyDictionary<string, MailMergeValue>>>(StringComparer.OrdinalIgnoreCase)
{
["CarEquipments"] = new[]
{
new Dictionary<string, MailMergeValue>(StringComparer.OrdinalIgnoreCase)
{
["Name"] = new MailMergeValue.Text("Vinterhjul"),
["Price"] = new MailMergeValue.Text("8.000 kr.")
},
new Dictionary<string, MailMergeValue>(StringComparer.OrdinalIgnoreCase)
{
["Name"] = new MailMergeValue.Text("Adaptiv fartpilot"),
["Price"] = new MailMergeValue.Text("12.000 kr.")
}
}
});
MailMergeEngine.MergeFile("template.docx", "merged.docx", data);
For an in-memory merge:
byte[] templateBytes = File.ReadAllBytes("template.docx");
byte[] mergedDocx = MailMergeEngine.Merge(templateBytes, data);
For stream-oriented code:
using var template = File.OpenRead("template.docx");
using var merged = File.Create("merged.docx");
MailMergeEngine.Merge(template, merged, data);
Merge And Convert To PDF
For the common server flow, merge first and pass the merged DOCX bytes straight into the converter:
byte[] templateBytes = File.ReadAllBytes("template.docx");
byte[] mergedDocx = MailMergeEngine.Merge(templateBytes, data);
byte[] pdfBytes = Tpdf.ConvertDocxToPdf(mergedDocx);
Or use the combined helper:
Tpdf.ConvertMailMergeTemplateToPdf("template.docx", "output.pdf", data);
byte[] pdfBytes = Tpdf.ConvertMailMergeTemplateToPdf("template.docx", data);
The combined helper does not require the caller to save merged.docx. Internally it renders the merged DOCX in memory, writes a temporary DOCX for the native TPDF converter, reads or writes the PDF result, and removes the temporary folder.
Template Support
TPDF.MailMerge is designed for Word mail-merge templates and aims to match common Aspose.Words mail-merge output. Aspose is not used at runtime. It supports:
- Regular Word
MERGEFIELDfields. - Repeating regions using
TableStart:RegionNameandTableEnd:RegionName. - Image fields such as
Image:LogoStreamwith PNG byte values. - Word
IFfield structures used in mail-merge templates. - Headers, footers, text boxes, VML/DrawingML image placeholders, and common OpenXML field shapes.
It does not use the custom <<[Field]>> syntax. That syntax was only used by internal comparison tooling.
Data Model
MailMergeData.Fields supplies single-record values:
["OrderId"] = new MailMergeValue.Text("TPDF-ORDER-001")
MailMergeData.Regions supplies repeated rows for fields wrapped in TableStart: / TableEnd::
["Items"] = new[]
{
new Dictionary<string, MailMergeValue>
{
["Name"] = new MailMergeValue.Text("Line item"),
["Price"] = new MailMergeValue.Text("100 kr.")
}
}
For image merge fields, the template field is usually named Image:LogoStream, while the data key is LogoStream:
["LogoStream"] = new MailMergeValue.ImagePng(File.ReadAllBytes("logo.png"))
Runtime Lifecycle
Tpdf.Initialize() is optional. Call it during application startup if you want to warm up the runtime and catch startup/configuration errors early. If you skip it, the first conversion initializes the runtime automatically.
Tpdf.Initialize();
TPDF uses a process-lifetime LibreOffice runtime singleton and does not spawn soffice. Conversions are serialized internally to respect the embedded LibreOffice runtime contract.
Tpdf.Shutdown() exists for API completeness, but native runtime unload is not currently supported.
Deployment Notes
The NuGet package copies:
TPDF.Managed.dllTPDF.MailMerge.dlllibtpdf.soon Linux, ortpdf.dllon Windows- the sibling
tpdf-runtimefolder required by the converter
For app deployment, publish/copy the application output folder with those runtime files intact.
| 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 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. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.4.22 | 326 | 6/26/2026 |
| 0.4.21 | 113 | 6/26/2026 |
| 0.4.20 | 129 | 6/22/2026 |
| 0.4.19 | 138 | 6/19/2026 |
| 0.4.18 | 118 | 6/17/2026 |
| 0.4.17 | 113 | 6/15/2026 |
| 0.4.16 | 106 | 6/11/2026 |
| 0.4.15 | 101 | 6/11/2026 |
| 0.4.14 | 110 | 6/11/2026 |
| 0.4.13 | 115 | 6/10/2026 |
| 0.4.12 | 107 | 6/10/2026 |
| 0.4.11 | 108 | 6/10/2026 |
| 0.4.10 | 115 | 6/8/2026 |
| 0.4.9 | 102 | 6/8/2026 |
| 0.4.8 | 107 | 6/8/2026 |
| 0.4.7 | 107 | 6/8/2026 |
| 0.4.6 | 120 | 5/25/2026 |
| 0.4.5 | 101 | 5/23/2026 |
| 0.4.4 | 104 | 5/23/2026 |
| 0.4.3 | 106 | 5/23/2026 |