Saitec.PdfDsl 2.0.1.4

dotnet add package Saitec.PdfDsl --version 2.0.1.4
                    
NuGet\Install-Package Saitec.PdfDsl -Version 2.0.1.4
                    
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="Saitec.PdfDsl" Version="2.0.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Saitec.PdfDsl" Version="2.0.1.4" />
                    
Directory.Packages.props
<PackageReference Include="Saitec.PdfDsl" />
                    
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 Saitec.PdfDsl --version 2.0.1.4
                    
#r "nuget: Saitec.PdfDsl, 2.0.1.4"
                    
#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 Saitec.PdfDsl@2.0.1.4
                    
#: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=Saitec.PdfDsl&version=2.0.1.4
                    
Install as a Cake Addin
#tool nuget:?package=Saitec.PdfDsl&version=2.0.1.4
                    
Install as a Cake Tool

Saitec.PdfDsl

Saitec.PdfDsl is a lightweight, extensible domain-specific language (DSL) designed to generate PDF documents using simple text instructions.
It is built on top of PdfSharp, offering a clean abstraction between what is described (the DSL) and how it is rendered (PdfSharp drawing engine).

This library is ideal for creating printable documents such as:

  • Invoices
  • Manifests
  • Packing lists
  • Labels
  • Logistics reports
  • Operational forms
  • Structured documents driven from templates, files, or databases

✨ Features

✔ DSL-based PDF generation

Describe PDFs using text commands like:

TXT:10,10,Hello
LINE:10,20,200,20
IMG:path,10,30,50,50
TBL-START:10,40,2,2;40,80,40
CELL:Product A
CELL:10
TBL-END

✔ Extensible command system

You can register new commands via:

PdfCommandFactory.Register("MYCMD", (args, cfg) => new MyCustomCommand(args));

✔ Tables with rich features

  • Column widths
  • Row height calculation
  • Multi-line text wrapping
  • Column spanning
  • Cell padding & spacing
  • Background colors
  • Captions
  • Repeating header rows on every new page

✔ Pagination

Automatic page breaks when content or table rows overflow the page.

Footers use the same DSL commands, including support for templates:

FOOTER-TEMPLATE:#TEMPLATE Page #PAGE-NUMBER# of #TOTAL-PAGES#

📜 DSL Examples

Basic Text and Lines

SETTING:PAGESIZE:21,29.7
SETTING:MARGIN-TOP:10
SETTING:MARGIN-BOTTOM:10

TXT 10,10,Hello World
LINE 10,20,200,20
RIGHTTXT 10,200,20,Aligned to the right

Images

IMG C:/logos/mylogo.png,10,30,50,30

Simple Table

TBL-START:10,50,2,2;30,100,50

CELL:ID
CELL:Name
CELL:Qty

CELL:1
CELL:Product A
CELL:10

CELL:2
CELL:Product B
CELL:25

TBL-END

Table With Header Row (Repeated on Each Page)

TBL-START:10,50,2,2;40,80,40

TBL-HEADER-START
CELL:START:1:RGB:220,220,220;ID
CELL:CENTER:1:RGB:220,220,220;Description
CELL:END:1:RGB:220,220,220;Qty
TBL-HEADER-END

CELL:1
CELL:Product A
CELL:10

CELL:2
CELL:Product B
CELL:25

CELL:3
CELL:Product C
CELL:18

TBL-END
FOOTER-TEMPLATE:#TEMPLATE Page #PAGE-NUMBER# of #TOTAL-PAGES#
FOOTER-TEMPLATE:TXT:10,BOTTOM-10,Generated by Saitec.PdfDsl

📦 Installation

Install via NuGet:

dotnet add package Saitec.PdfDsl

Or NuGet Package Manager:

Install-Package Saitec.PdfDsl

🧩 Basic C# Usage

var basePath = Path.Combine(AppContext.BaseDirectory, "pdf-output");
var generator = new PdfFileGenerator(basePath);

var dslLines = new List<string> {
    "SETTING:PAGESIZE:21,29.7",
    "TXT 10,10,Hello from Saitec.PdfDsl",
    "LINE 10,20,200,20",
    "TBL-START:10,30,2,2;40,80,40",
    "TBL-HEADER-START",
    "CELL:START:1:RGB:220,220,220;ID",
    "CELL:START:2:RGB:220,220,220;Description",
    "TBL-HEADER-END",
    "CELL:1",
    "CELL:Item A",
    "CELL:10",
    "TBL-END"
};

var filePath = generator.GeneratePdf(dslLines);
Console.WriteLine($"PDF generated at: {filePath}");

🔧 Extending PdfDsl

To add a new command:

  1. Create a class implementing IPdfCommand
  2. Register it in PdfCommandFactory

Example:

public sealed class HelloCommand : IPdfCommand {
    public void Execute(PdfRenderContext ctx) {
        ctx.DrawString(20, 20, "Hello!", ctx.DefaultFont);
    }
}

// Registration
PdfCommandFactory.Register("HELLO", (args, cfg) => new HelloCommand());

Now DSL users can write:

HELLO

🧪 Testing

The DSL engine is fully testable:

✔ Parser tests

Verify that DSL lines produce correct IPdfCommand objects.

✔ Rendering tests

Use a mock/fake PdfRenderContext to verify:

  • Coordinates
  • Page creation
  • Table splitting
  • Header repetition
  • Footer replaying

✔ Integration tests

Render real PDFs and compare:

  • Page count
  • Bounding boxes
  • Table heights
  • Line counts

🚀 Use Cases

  • Logistics & warehouse documents
  • Invoicing systems
  • Government forms
  • Label printers
  • Multi-page reports
  • Email-generated PDFs
  • Custom templating engines

📘 License (MIT)

MIT License

Copyright (c) 2025 Saitec Ingeniería S.A.S., Colombia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights  
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell     
copies of the Software, and to permit persons to whom the Software is        
furnished to do so, subject to the following conditions:                      

The above copyright notice and this permission notice shall be included in    
all copies or substantial portions of the Software.                           

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR   
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,      
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE   
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER        
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING       
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER          
DEALINGS IN THE SOFTWARE.                                                     

❤️ Contributing

Contributions are welcome!

You can:

  • Submit pull requests
  • Propose new DSL commands
  • Improve documentation
  • Create examples and templates
  • Suggest improvements

⭐ Support

If you find Saitec.PdfDsl useful, please star the repository — it helps others discover the project!


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

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
2.0.1.4 516 12/1/2025
2.0.1.3 497 12/1/2025

# PdfDsl v2.0.1.4