SemanticXamlPrint 4.1.0

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

SemanticXamlPrint

SemanticXamlPrint helps you build printable documents (receipts, invoices, reports) using a simple XML/XAML-like template.

Instead of hardcoding drawing coordinates, you define your layout once and render it to:

  • System.Drawing print output
  • PDF (PdfSharp)
  • PDF for .NET Core (PdfSharpCore)

Why Use It?

  • Fast template-driven document design
  • Great for thermal receipts and A4 layouts
  • Shared structure across Print and PDF outputs
  • Supports nested grids, text wrapping, images, QR codes, borders, and line breaks
  • Supports fixed-height or page-filling invoice item grids (A4-friendly)

Install

NuGet:

Install-Package SemanticXamlPrint

Package: https://nuget.org/packages/SemanticXamlPrint

Quick Integration Guide

1. Create a template file

Example invoice.template:

<Template Font="Calibri" FontSize="10" Document="A4" MarginTop="20" MarginBottom="20" MarginLeft="20" MarginRight="20">

  <Grid ColumnWidths="6*1.5*1.5*1.5" BorderStyle="Solid" HeightMode="FillRemaining" BottomReserve="120">
    <GridRow>
      <Data Grid.Column="0" FontStyle="Bold" Align="Center">DESCRIPTION</Data>
      <Data Grid.Column="1" FontStyle="Bold" Align="Center">HOURS</Data>
      <Data Grid.Column="2" FontStyle="Bold" Align="Center">RATE</Data>
      <Data Grid.Column="3" FontStyle="Bold" Align="Center">AMOUNT</Data>
    </GridRow>

    <GridRow>
      <Data Grid.Column="0">Test Example</Data>
      <Data Grid.Column="1" Align="Center">2</Data>
      <Data Grid.Column="2" Align="Right">1,200</Data>
      <Data Grid.Column="3" Align="Right">2,400</Data>
    </GridRow>
  </Grid>

</Template>

2. Parse the template

byte[] xamlFileBytes = File.ReadAllBytes("invoice.template");
IXamlComponent xamlComponent = DefaultXamlParser.Parse(xamlFileBytes);

3. Render to your target

PrintDocument (System.Drawing):

PrintDocument printDocument = new PrintDocument();
printDocument.PrintPage += (sender, eventArgs) =>
{
    eventArgs.DrawXamlComponent(xamlComponent);
};
printDocument.Print();

PDF (SemanticXamlPrint.PDF):

using (PdfSharp.Pdf.PdfDocument document = new PdfSharp.Pdf.PdfDocument())
{
    document.DrawXamlComponent(xamlComponent);
    document.Save("output.pdf");
}

PDF .NET Core (SemanticXamlPrint.PDF.NetCore):

using (PdfSharpCore.Pdf.PdfDocument document = new PdfSharpCore.Pdf.PdfDocument())
{
    document.DrawXamlComponent(xamlComponent);
    document.Save("outputcore.pdf");
}

A4 Invoice Grid Stretch (Fill Remaining Page)

For invoice designs where the items table should occupy the remaining page height:

<Grid ColumnWidths="6*1.5*1.5*1.5" BorderStyle="Solid" HeightMode="FillRemaining" BottomReserve="120">
  
</Grid>

Notes:

  • HeightMode="FillRemaining": expands the grid down to page bottom
  • BottomReserve="120": keeps free space for totals/footer/signature
  • MinHeight="300": optional minimum grid height fallback

Usage Example (Basic Receipt)

class Program
{
    static void Main(string[] args)
    {
        byte[] xamlFileBytes = File.ReadAllBytes("custom.grid.template");
        IXamlComponent xamlComponent = DefaultXamlParser.Parse(xamlFileBytes);

        PrintDocument printDocument = new PrintDocument();
        printDocument.PrintPage += (obj, eventArgs) =>
        {
            eventArgs.DrawXamlComponent(xamlComponent);
        };
        printDocument.Print();
    }
}

Result

Result

Supported Template Components

1. Template

<Template Font="Calibri" FontSize="10" MarginTop="10">
   
</Template>

2. Data

<Data FontStyle="Bold" FontSize="11" TextWrap="True" Align="Center">Centered wrapped text</Data>

3. Image

<Image Source="logo.png" Width="100" Height="100" />

4. Grid + GridRow

<Grid ColumnWidths="1*4*2" BorderStyle="Solid">
  <GridRow>
    <Data Grid.Column="0" FontStyle="Bold">Column 1</Data>
    <Data Grid.Column="1" FontStyle="Bold">Column 2</Data>
    <Data Grid.Column="2" FontStyle="Bold" Align="Right">Column 3</Data>
  </GridRow>
</Grid>

5. Cells + Cell

<Cells>
  <Cell FontStyle="Bold" X="0">ITEM DESC.</Cell>
  <Cell FontStyle="Bold" X="120">RATE</Cell>
  <Cell FontStyle="Bold" X="170">QTY</Cell>
  <Cell FontStyle="Bold" X="220">AMOUNT</Cell>
</Cells>

6. QRCode

<QRCode Text="https://example.com/invoice/1001" Width="100" Height="100" />

7. Line

<Line Style="Dash" />

8. LineBreak

<LineBreak />

More Examples

Demo projects:

Starter Templates

Use these as quick copy/paste starting points.

1. Receipt (Thermal Style)

<Template Font="Calibri" FontSize="10" MarginTop="10" MarginLeft="5" MarginRight="5">
  <Data Align="Center" FontStyle="Bold" FontSize="12">MY STORE</Data>
  <Data Align="Center">123 Main Street</Data>
  <LineBreak />
  <Line />
  <Grid ColumnWidths="1*4*2">
    <GridRow>
      <Data Grid.Column="0" FontStyle="Bold">QTY</Data>
      <Data Grid.Column="1" FontStyle="Bold">ITEM</Data>
      <Data Grid.Column="2" FontStyle="Bold" Align="Right">AMOUNT</Data>
    </GridRow>
    <GridRow>
      <Data Grid.Column="0">1</Data>
      <Data Grid.Column="1" TextWrap="True">Coffee</Data>
      <Data Grid.Column="2" Align="Right">3.50</Data>
    </GridRow>
  </Grid>
  <Line />
  <Data Align="Right" FontStyle="Bold">TOTAL: 3.50</Data>
  <LineBreak />
  <Data Align="Center">Thank you!</Data>
</Template>

2. Invoice (A4, Fill Remaining Items Grid)

<Template Font="Calibri" FontSize="10" Document="A4" MarginTop="20" MarginBottom="20" MarginLeft="20" MarginRight="20">
  <Grid ColumnWidths="1*1">
    <GridRow>
      <Data Grid.Column="0" FontStyle="Bold" FontSize="16">[Your Company Name]</Data>
      <Data Grid.Column="1" Align="Right" FontStyle="Bold" FontSize="18">INVOICE</Data>
    </GridRow>
  </Grid>
  <LineBreak />
  <Grid ColumnWidths="6*1.5*1.5*1.5" BorderStyle="Solid" HeightMode="FillRemaining" BottomReserve="120">
    <GridRow>
      <Data Grid.Column="0" FontStyle="Bold" Align="Center">DESCRIPTION</Data>
      <Data Grid.Column="1" FontStyle="Bold" Align="Center">HOURS</Data>
      <Data Grid.Column="2" FontStyle="Bold" Align="Center">RATE</Data>
      <Data Grid.Column="3" FontStyle="Bold" Align="Center">AMOUNT</Data>
    </GridRow>
    <GridRow>
      <Data Grid.Column="0">Test Example</Data>
      <Data Grid.Column="1" Align="Center">2</Data>
      <Data Grid.Column="2" Align="Right">1,200</Data>
      <Data Grid.Column="3" Align="Right">2,400</Data>
    </GridRow>
  </Grid>
  <Data Align="Right" FontStyle="Bold">TOTAL: 2,400</Data>
</Template>

3. Report (Section + Summary)

<Template Font="Calibri" FontSize="10" Document="A4" MarginTop="20" MarginBottom="20" MarginLeft="20" MarginRight="20">
  <Data FontStyle="Bold" FontSize="14">Monthly Sales Report</Data>
  <Data>Period: January 2026</Data>
  <LineBreak />
  <Grid ColumnWidths="3*2*2" BorderStyle="Solid">
    <GridRow>
      <Data Grid.Column="0" FontStyle="Bold">Category</Data>
      <Data Grid.Column="1" FontStyle="Bold" Align="Right">Orders</Data>
      <Data Grid.Column="2" FontStyle="Bold" Align="Right">Revenue</Data>
    </GridRow>
    <GridRow>
      <Data Grid.Column="0">Beverages</Data>
      <Data Grid.Column="1" Align="Right">120</Data>
      <Data Grid.Column="2" Align="Right">4,800.00</Data>
    </GridRow>
  </Grid>
  <LineBreak />
  <Data Align="Right" FontStyle="Bold">Grand Total: 4,800.00</Data>
</Template>
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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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
4.1.0 135 5/23/2026
4.0.2 382 1/21/2024
4.0.1 357 8/5/2023
3.3.3 321 6/24/2023
3.3.2 330 5/26/2023
3.1.3 343 4/30/2023
3.1.2 355 4/15/2023
2.0.3 374 4/8/2023
2.0.2 365 4/8/2023
2.0.1 365 4/7/2023