This example demonstrates how to programmatically create an invoice with NOV Rich Text.
The invoice includes supplier and customer information, supplier email and website, invoice dates, a line-item table, subtotal and sales tax, bank details, a payment QR code, and a page header and footer.
All company, bank, and payment details in this example are fictional.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Barcode;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Text;
using Nevron.Nov.Text.Formats;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NSampleInvoice1Example";
// Create the NOV example and its controls
NWidget exampleContent = CreateExampleContent();
NWidget exampleControls = CreateExampleControls();
if (exampleControls != null)
{
exampleControls.PreferredWidth = 300;
}
// Place the example and its controls in a pair box
NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
pairBox.FillMode = ENStackFillMode.First;
pairBox.FitMode = ENStackFitMode.First;
pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);
// Host the example in the form
NNovWidgetHost host = new NNovWidgetHost(pairBox);
host.Dock = DockStyle.Fill;
Controls.Add(host);
}
#endregion
#region Example
private NWidget CreateExampleContent()
{
return null;
}
private NWidget CreateExampleControls()
{
return null;
}
#endregion
#region Implementation
private static InvoiceData CreateSampleInvoice()
{
// All company, bank, and payment details are fictional.
Party supplier = new Party(
"BluePeak Cloud Services, Inc.",
"250 Cloud Avenue",
"Seattle, WA 98101",
"United States",
"91-7463058",
"billing@bluepeak.example",
"https://bluepeak.example/");
Party customer = new Party(
"Cedarbridge Design, Inc.",
"120 Market Street",
"Portland, OR 97201",
"United States",
"93-0000000",
"",
"");
InvoiceLine[] lines =
{
new InvoiceLine("CLOUD-01", "Managed cloud hosting",
"01.09.2026 - 30.09.2026", 1m, "month", 240m),
new InvoiceLine("BACKUP-01", "Cloud backup and recovery",
"01.09.2026 - 30.09.2026", 1m, "month", 60m),
new InvoiceLine("SUPPORT-01", "Technical support",
"September 2026", 3m, "hour", 85m)
};
return new InvoiceData(
"INV-2026-0091",
new DateTime(2026, 9, 21),
new DateTime(2026, 9, 21),
new DateTime(2026, 10, 5),
"PO-2026-104",
customer,
supplier,
lines,
0m,
"USD",
"Example Commercial Bank",
"000000000",
"0000000000",
"Business checking",
"Alex Morgan",
"https://bluepeak.example/pay/INV-2026-0091");
}
private void PopulateRichText()
{
PopulateInvoice(m_RichText, CreateSampleInvoice());
}
private static void PopulateInvoice(NRichTextView view, InvoiceData invoice)
{
view.Content.Sections.Clear();
var section = new NSection
{
PageSize = new NPaperSize(ENPaperKind.A4),
PageMargins = new NMargins(36, 36, 36, 42)
};
view.Content.Sections.Add(section);
AddHeader(section, invoice.Supplier);
AddFooter(section);
AddSupplierAndCustomer(section, invoice);
AddInvoiceIdentity(section, invoice);
AddLineItems(section, invoice);
AddTotals(section, invoice);
AddPaymentSection(section, invoice);
}
// SECTION 1 - company heading and customer/supplier information
private static void AddSupplierAndCustomer(NSection section, InvoiceData x)
{
var contact = new NTable(0, 2)
{
Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
};
contact.Columns[0].PreferredWidth =
new NMultiLength(ENMultiLengthUnit.Percentage, 65);
contact.Columns[1].PreferredWidth =
new NMultiLength(ENMultiLengthUnit.Percentage, 35);
var contactRow = new NTableRow();
var brandCell = new NTableCell { Padding = new NMargins(5) };
var brandParagraph = new NParagraph
{
HorizontalAlignment = ENAlign.Left,
Margins = new NMargins(0, 0, 0, 1)
};
brandParagraph.Inlines.Add(new NTextInline(x.Supplier.Name)
{
FontSize = 15,
FontStyle = ENFontStyle.Bold
});
brandCell.Blocks.Add(brandParagraph);
var sloganParagraph = new NParagraph
{
HorizontalAlignment = ENAlign.Left,
Margins = new NMargins(0, 0, 0, 1)
};
sloganParagraph.Inlines.Add(new NTextInline("Global expertise, local outcomes")
{
FontSize = 15,
FontStyle = ENFontStyle.Bold
});
brandCell.Blocks.Add(sloganParagraph);
contactRow.Cells.Add(brandCell);
var contactCell = new NTableCell { Padding = new NMargins(5) };
var emailParagraph = new NParagraph
{
HorizontalAlignment = ENAlign.Right,
Margins = new NMargins(0, 0, 0, 1)
};
emailParagraph.Inlines.Add(new NTextInline(x.Supplier.Email)
{
FontSize = 10,
FontStyle = ENFontStyle.Regular
});
contactCell.Blocks.Add(emailParagraph);
var websiteParagraph = new NParagraph
{
HorizontalAlignment = ENAlign.Right,
Margins = new NMargins(0, 0, 0, 1)
};
websiteParagraph.Inlines.Add(new NTextInline(x.Supplier.Website)
{
FontSize = 10,
FontStyle = ENFontStyle.Regular
});
contactCell.Blocks.Add(websiteParagraph);
contactRow.Cells.Add(contactCell);
contact.Rows.Add(contactRow);
section.Blocks.Add(contact);
section.Blocks.Add(new NParagraph
{
Margins = new NMargins(0, 0, 0, 14)
});
var parties = new NTable(0, 2)
{
Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
};
var partiesRow = new NTableRow();
Party[] partyValues = { x.Customer, x.Supplier };
string[] captions = { "CUSTOMER:", "SUPPLIER:" };
ENAlign[] alignments = { ENAlign.Left, ENAlign.Right };
for (int i = 0; i < partyValues.Length; i++)
{
Party party = partyValues[i];
ENAlign alignment = alignments[i];
var partyCell = new NTableCell { Padding = new NMargins(5) };
string[] lines =
{
captions[i], party.Name, party.Address1, party.Address2,
party.Country, $"EIN: {party.Ein}"
};
for (int lineIndex = 0; lineIndex < lines.Length; lineIndex++)
{
var paragraph = new NParagraph
{
HorizontalAlignment = alignment,
Margins = new NMargins(0, 0, 0, 1)
};
paragraph.Inlines.Add(new NTextInline(lines[lineIndex])
{
FontSize = 10,
FontStyle = lineIndex < 2
? ENFontStyle.Bold
: ENFontStyle.Regular
});
partyCell.Blocks.Add(paragraph);
}
partiesRow.Cells.Add(partyCell);
}
parties.Rows.Add(partiesRow);
section.Blocks.Add(parties);
section.Blocks.Add(new NParagraph
{
Margins = new NMargins(0, 0, 0, 16)
});
}
// SECTION 2 - invoice title, dates and reference
private static void AddInvoiceIdentity(NSection section, InvoiceData x)
{
var title = new NParagraph
{
HorizontalAlignment = ENAlign.Center,
Margins = new NMargins(0, 0, 0, 1)
};
title.Inlines.Add(new NTextInline("INVOICE")
{
FontSize = 24,
FontStyle = ENFontStyle.Bold
});
section.Blocks.Add(title);
var original = new NParagraph
{
HorizontalAlignment = ENAlign.Center,
Margins = new NMargins(0, 0, 0, 1)
};
original.Inlines.Add(new NTextInline("ORIGINAL")
{
FontSize = 16,
FontStyle = ENFontStyle.Bold
});
section.Blocks.Add(original);
var number = new NParagraph
{
HorizontalAlignment = ENAlign.Center,
Margins = new NMargins(0, 0, 0, 1)
};
number.Inlines.Add(new NTextInline($"No. {x.Number} / {x.IssueDate:dd.MM.yyyy}")
{
FontSize = 12,
FontStyle = ENFontStyle.Bold
});
section.Blocks.Add(number);
var metadata = new NTable(0, 3)
{
Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
};
var metadataRow = new NTableRow();
string[] metadataValues =
{
$"Tax point date: {x.TaxPointDate:dd.MM.yyyy}",
$"Due date: {x.DueDate:dd.MM.yyyy}",
$"Customer reference: {x.CustomerReference}"
};
ENAlign[] metadataAlignments =
{
ENAlign.Left, ENAlign.Center, ENAlign.Right
};
for (int i = 0; i < metadataValues.Length; i++)
{
var cell = new NTableCell { Padding = new NMargins(5) };
var paragraph = new NParagraph
{
HorizontalAlignment = metadataAlignments[i],
Margins = new NMargins(0, 0, 0, 1)
};
paragraph.Inlines.Add(new NTextInline(metadataValues[i])
{
FontSize = 10,
FontStyle = ENFontStyle.Bold
});
cell.Blocks.Add(paragraph);
metadataRow.Cells.Add(cell);
}
metadata.Rows.Add(metadataRow);
section.Blocks.Add(metadata);
section.Blocks.Add(new NParagraph
{
Margins = new NMargins(0, 0, 0, 8)
});
}
// SECTION 3 - line-item table
private static void AddLineItems(NSection section, InvoiceData x)
{
var table = new NTable(0, 6)
{
Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
};
double[] widths = { 4, 49, 8, 9, 15, 15 };
for (int i = 0; i < widths.Length; i++)
{
table.Columns[i].PreferredWidth =
new NMultiLength(ENMultiLengthUnit.Percentage, widths[i]);
}
var headerRow = new NTableRow();
string[] headers =
{
"No.", "Description of goods/services", "Qty", "Unit",
"Unit price", "Amount"
};
ENAlign[] headerAlignments =
{
ENAlign.Left, ENAlign.Left, ENAlign.Right,
ENAlign.Left, ENAlign.Right, ENAlign.Right
};
for (int i = 0; i < headers.Length; i++)
{
var cell = new NTableCell
{
Padding = new NMargins(5),
BackgroundFill = new NColorFill(HeaderGray)
};
var paragraph = new NParagraph
{
HorizontalAlignment = headerAlignments[i],
Margins = new NMargins(0, 0, 0, 1)
};
paragraph.Inlines.Add(new NTextInline(headers[i])
{
FontSize = 10,
FontStyle = ENFontStyle.Bold
});
cell.Blocks.Add(paragraph);
headerRow.Cells.Add(cell);
}
table.Rows.Add(headerRow);
for (int lineIndex = 0; lineIndex < x.Lines.Count; lineIndex++)
{
InvoiceLine line = x.Lines[lineIndex];
decimal amount = line.Quantity * line.UnitPrice;
string[] values =
{
(lineIndex + 1).ToString(En),
$"{line.Code}\n{line.Description}\n{line.Period}",
line.Quantity.ToString("N2", En),
line.Unit,
$"{line.UnitPrice.ToString("N2", En)} {x.Currency}",
$"{amount.ToString("N2", En)} {x.Currency}"
};
ENAlign[] alignments =
{
ENAlign.Left, ENAlign.Left, ENAlign.Right,
ENAlign.Left, ENAlign.Right, ENAlign.Right
};
var row = new NTableRow();
for (int columnIndex = 0; columnIndex < values.Length; columnIndex++)
{
var cell = new NTableCell { Padding = new NMargins(5) };
foreach (string textLine in values[columnIndex].Split('\n'))
{
var paragraph = new NParagraph
{
HorizontalAlignment = alignments[columnIndex],
Margins = new NMargins(0, 0, 0, 1)
};
paragraph.Inlines.Add(new NTextInline(textLine)
{
FontSize = 10,
FontStyle = ENFontStyle.Regular
});
cell.Blocks.Add(paragraph);
}
row.Cells.Add(cell);
}
table.Rows.Add(row);
}
section.Blocks.Add(table);
section.Blocks.Add(new NParagraph
{
Margins = new NMargins(0, 0, 0, 8)
});
}
// SECTION 4 - subtotal, optional sales tax and total
private static void AddTotals(NSection section, InvoiceData x)
{
decimal net = 0;
foreach (InvoiceLine line in x.Lines)
{
net += line.Quantity * line.UnitPrice;
}
decimal salesTax = Math.Round(net * x.SalesTaxRate, 2);
decimal gross = net + salesTax;
var outer = new NTable(0, 2)
{
Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
};
outer.Columns[0].PreferredWidth =
new NMultiLength(ENMultiLengthUnit.Percentage, 52);
outer.Columns[1].PreferredWidth =
new NMultiLength(ENMultiLengthUnit.Percentage, 48);
var outerRow = new NTableRow();
var emptyCell = new NTableCell { Padding = new NMargins(5) };
var emptyParagraph = new NParagraph
{
HorizontalAlignment = ENAlign.Left,
Margins = new NMargins(0, 0, 0, 1)
};
emptyParagraph.Inlines.Add(new NTextInline(string.Empty)
{
FontSize = 10,
FontStyle = ENFontStyle.Regular
});
emptyCell.Blocks.Add(emptyParagraph);
outerRow.Cells.Add(emptyCell);
var totalsCell = new NTableCell();
var totals = new NTable(0, 3)
{
Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
};
var totalRows = new List
{
new TotalRow("Invoice subtotal:", $"{net.ToString("N2", En)} {x.Currency}",
$"{net.ToString("N2", En)} {x.Currency}", false)
};
if (x.SalesTaxRate > 0)
{
totalRows.Add(new TotalRow("Sales tax rate:",
x.SalesTaxRate.ToString("P2", En), string.Empty, false));
totalRows.Add(new TotalRow("Sales tax:",
$"{salesTax.ToString("N2", En)} {x.Currency}",
$"{salesTax.ToString("N2", En)} {x.Currency}", false));
}
totalRows.Add(new TotalRow("TOTAL:", $"{gross.ToString("N2", En)} {x.Currency}",
$"{gross.ToString("N2", En)} {x.Currency}", true));
foreach (TotalRow totalRow in totalRows)
{
string label = totalRow.Label;
string middle = totalRow.Middle;
string strong = totalRow.Strong;
bool bold = totalRow.Bold;
var row = new NTableRow();
string[] values = { label, middle, strong };
for (int i = 0; i < values.Length; i++)
{
var cell = new NTableCell { Padding = new NMargins(5) };
if (i == 2 && values[i].Length > 0)
{
cell.BackgroundFill = new NColorFill(HeaderGray);
}
var paragraph = new NParagraph
{
HorizontalAlignment = ENAlign.Right,
Margins = new NMargins(0, 0, 0, 1)
};
paragraph.Inlines.Add(new NTextInline(values[i])
{
FontSize = 10,
FontStyle = bold || i == 2
? ENFontStyle.Bold
: ENFontStyle.Regular
});
cell.Blocks.Add(paragraph);
row.Cells.Add(cell);
}
totals.Rows.Add(row);
}
totalsCell.Blocks.Add(totals);
outerRow.Cells.Add(totalsCell);
outer.Rows.Add(outerRow);
section.Blocks.Add(outer);
section.Blocks.Add(new NParagraph
{
Margins = new NMargins(0, 0, 0, 22)
});
}
// SECTION 5 - bank details, payment summary and QR widget
private static void AddPaymentSection(NSection section, InvoiceData x)
{
decimal net = 0;
foreach (InvoiceLine line in x.Lines)
{
net += line.Quantity * line.UnitPrice;
}
decimal salesTax = Math.Round(
net * x.SalesTaxRate, 2, MidpointRounding.AwayFromZero);
decimal total = net + salesTax;
var table = new NTable(0, 3)
{
Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
};
table.Columns[0].PreferredWidth =
new NMultiLength(ENMultiLengthUnit.Percentage, 53);
table.Columns[1].PreferredWidth =
new NMultiLength(ENMultiLengthUnit.Percentage, 27);
table.Columns[2].PreferredWidth =
new NMultiLength(ENMultiLengthUnit.Percentage, 20);
var row = new NTableRow();
var bankCell = new NTableCell { Padding = new NMargins(5) };
string[] bankLines =
{
"BANK DETAILS:", x.BankName,
$"ABA routing number: {x.RoutingNumber}",
$"Account number: {x.AccountNumber}",
$"Account type: {x.AccountType}"
};
for (int i = 0; i < bankLines.Length; i++)
{
var paragraph = new NParagraph
{
HorizontalAlignment = ENAlign.Left,
Margins = new NMargins(0, 0, 0, 1)
};
paragraph.Inlines.Add(new NTextInline(bankLines[i])
{
FontSize = i == 1 ? 12 : 10,
FontStyle = i < 2 ? ENFontStyle.Bold : ENFontStyle.Regular
});
bankCell.Blocks.Add(paragraph);
}
row.Cells.Add(bankCell);
var detailsCell = new NTableCell { Padding = new NMargins(5) };
string[] detailLines =
{
$"Amount due: {total.ToString("N2", En)} {x.Currency}",
"Exchange rate: 1.00000",
$"Prepared by: {x.PreparedBy}",
"Scan to pay:"
};
for (int i = 0; i < detailLines.Length; i++)
{
var paragraph = new NParagraph
{
HorizontalAlignment = ENAlign.Left,
Margins = new NMargins(0, 0, 0, 1)
};
paragraph.Inlines.Add(new NTextInline(detailLines[i])
{
FontSize = 10,
FontStyle = i == 0 || i == 3
? ENFontStyle.Bold
: ENFontStyle.Regular
});
detailsCell.Blocks.Add(paragraph);
}
row.Cells.Add(detailsCell);
var qrCell = new NTableCell { Padding = new NMargins(5) };
var qrParagraph = new NParagraph
{
HorizontalAlignment = ENAlign.Center,
Margins = new NMargins(0, 0, 0, 1)
};
var qr = new NMatrixBarcode(ENMatrixBarcodeSymbology.QrCode, x.PaymentUrl)
{
ErrorCorrection = ENErrorCorrectionLevel.Medium,
PreferredSize = new NSize(92, 92)
};
qrParagraph.Inlines.Add(new NWidgetInline(qr));
qrCell.Blocks.Add(qrParagraph);
var qrCaption = new NParagraph
{
HorizontalAlignment = ENAlign.Center,
Margins = new NMargins(0, 0, 0, 1)
};
qrCaption.Inlines.Add(new NTextInline("Imaginary payment link")
{
FontSize = 8,
FontStyle = ENFontStyle.Regular
});
qrCell.Blocks.Add(qrCaption);
row.Cells.Add(qrCell);
table.Rows.Add(row);
section.Blocks.Add(table);
}
///
/// Header
///
///
private static void AddHeader(NSection section, Party supplier)
{
NHeaderFooter header = new NHeaderFooter();
header.Blocks.Add(new NParagraph(supplier.Name));
section.Header = header;
}
// SECTION 6 - repeating page footer
private static void AddFooter(NSection section)
{
var footer = new NHeaderFooter();
var table = new NTable(0, 2)
{
Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
};
var row = new NTableRow();
var noticeCell = new NTableCell { Padding = new NMargins(5) };
var noticeParagraph = new NParagraph
{
HorizontalAlignment = ENAlign.Left,
Margins = new NMargins(0, 0, 0, 1)
};
noticeParagraph.Inlines.Add(new NTextInline(
"This invoice was generated electronically and is valid without a signature.")
{
FontSize = 8,
FontStyle = ENFontStyle.Regular
});
noticeCell.Blocks.Add(noticeParagraph);
row.Cells.Add(noticeCell);
var pageCell = new NTableCell { Padding = new NMargins(5) };
var pageParagraph = new NParagraph
{
HorizontalAlignment = ENAlign.Right,
Margins = new NMargins(0, 0, 0, 1)
};
pageParagraph.Inlines.Add(new NTextInline("1/1")
{
FontSize = 8,
FontStyle = ENFontStyle.Regular
});
pageCell.Blocks.Add(pageParagraph);
row.Cells.Add(pageCell);
table.Rows.Add(row);
footer.Blocks.Add(table);
section.Footer = footer;
}
#endregion
#region Event Handlers
#endregion
#region Fields
private NRichTextView m_RichText;
private static readonly CultureInfo En = CultureInfo.GetCultureInfo("en-GB");
private static readonly NColor HeaderGray = NColor.FromRGB(225, 225, 225);
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
private sealed class Party
{
public Party(
string name,
string address1,
string address2,
string country,
string ein,
string email,
string website)
{
Name = name;
Address1 = address1;
Address2 = address2;
Country = country;
Ein = ein;
Email = email;
Website = website;
}
public readonly string Name;
public readonly string Address1;
public readonly string Address2;
public readonly string Country;
public readonly string Ein;
public readonly string Email;
public readonly string Website;
}
private sealed class InvoiceLine
{
public InvoiceLine(
string code,
string description,
string period,
decimal quantity,
string unit,
decimal unitPrice)
{
Code = code;
Description = description;
Period = period;
Quantity = quantity;
Unit = unit;
UnitPrice = unitPrice;
}
public readonly string Code;
public readonly string Description;
public readonly string Period;
public readonly decimal Quantity;
public readonly string Unit;
public readonly decimal UnitPrice;
}
private sealed class InvoiceData
{
public InvoiceData(
string number,
DateTime issueDate,
DateTime taxPointDate,
DateTime dueDate,
string customerReference,
Party customer,
Party supplier,
IList lines,
decimal salesTaxRate,
string currency,
string bankName,
string routingNumber,
string accountNumber,
string accountType,
string preparedBy,
string paymentUrl)
{
Number = number;
IssueDate = issueDate;
TaxPointDate = taxPointDate;
DueDate = dueDate;
CustomerReference = customerReference;
Customer = customer;
Supplier = supplier;
Lines = lines;
SalesTaxRate = salesTaxRate;
Currency = currency;
BankName = bankName;
RoutingNumber = routingNumber;
AccountNumber = accountNumber;
AccountType = accountType;
PreparedBy = preparedBy;
PaymentUrl = paymentUrl;
}
public readonly string Number;
public readonly DateTime IssueDate;
public readonly DateTime TaxPointDate;
public readonly DateTime DueDate;
public readonly string CustomerReference;
public readonly Party Customer;
public readonly Party Supplier;
public readonly IList Lines;
public readonly decimal SalesTaxRate;
public readonly string Currency;
public readonly string BankName;
public readonly string RoutingNumber;
public readonly string AccountNumber;
public readonly string AccountType;
public readonly string PreparedBy;
public readonly string PaymentUrl;
}
private sealed class TotalRow
{
public TotalRow(
string label,
string middle,
string strong,
bool bold)
{
Label = label;
Middle = middle;
Strong = strong;
Bold = bold;
}
public readonly string Label;
public readonly string Middle;
public readonly string Strong;
public readonly bool Bold;
}
#endregion
}
} | Language: VB.NET |
Imports Nevron.Nov
Imports Nevron.Nov.Barcode
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.Text
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Imports System
Imports System.Collections.Generic
Imports System.Globalization
Class MainWindow
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Title = "NOV WPF - NSampleInvoice1Example"
' Create the NOV example and its controls
Dim exampleContent As NWidget = CreateExampleContent()
Dim exampleControls As NWidget = CreateExampleControls()
If Not exampleControls Is Nothing Then
exampleControls.PreferredWidth = 300
End If
' Place the example and its controls in a pair box
Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
pairBox.FillMode = ENStackFillMode.First
pairBox.FitMode = ENStackFitMode.First
pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)
' Host the example in the form
Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
Content = host
End Sub
#End Region
#Region "Example"
Private Function CreateExampleControls() As NWidget
Return Nothing
End Function
Private Function CreateExampleContent() As NWidget
Return Nothing
End Function
#End Region
#Region "Implementation"
Private Shared Function CreateSampleInvoice() As InvoiceData
' All company, bank, and payment details are fictional.
Dim supplier As Party = New Party("BluePeak Cloud Services, Inc.", "250 Cloud Avenue", "Seattle, WA 98101", "United States", "91-7463058", "billing@bluepeak.example", "https://bluepeak.example/")
Dim customer As Party = New Party("Cedarbridge Design, Inc.", "120 Market Street", "Portland, OR 97201", "United States", "93-0000000", "", "")
Dim lines As InvoiceLine() = {New InvoiceLine("CLOUD-01", "Managed cloud hosting", "01.09.2026 - 30.09.2026", 1D, "month", 240D), New InvoiceLine("BACKUP-01", "Cloud backup and recovery", "01.09.2026 - 30.09.2026", 1D, "month", 60D), New InvoiceLine("SUPPORT-01", "Technical support", "September 2026", 3D, "hour", 85D)}
Return New InvoiceData("INV-2026-0091", New DateTime(2026, 9, 21), New DateTime(2026, 9, 21), New DateTime(2026, 10, 5), "PO-2026-104", customer, supplier, lines, 0D, "USD", "Example Commercial Bank", "000000000", "0000000000", "Business checking", "Alex Morgan", "https://bluepeak.example/pay/INV-2026-0091")
End Function
Private Sub PopulateRichText()
Call PopulateInvoice(m_RichText, CreateSampleInvoice())
End Sub
Private Shared Sub PopulateInvoice(view As NRichTextView, invoice As InvoiceData)
view.Content.Sections.Clear()
Dim section = New NSection With {
.PageSize = New NPaperSize(ENPaperKind.A4),
.PageMargins = New NMargins(36, 36, 36, 42)
}
view.Content.Sections.Add(section)
AddHeader(section, invoice.Supplier)
AddFooter(section)
AddSupplierAndCustomer(section, invoice)
AddInvoiceIdentity(section, invoice)
AddLineItems(section, invoice)
AddTotals(section, invoice)
AddPaymentSection(section, invoice)
End Sub
' SECTION 1 - company heading and customer/supplier information
Private Shared Sub AddSupplierAndCustomer(section As NSection, x As InvoiceData)
Dim contact = New NTable(0, 2) With {
.Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
}
contact.Columns(0).PreferredWidth = New NMultiLength(ENMultiLengthUnit.Percentage, 65)
contact.Columns(1).PreferredWidth = New NMultiLength(ENMultiLengthUnit.Percentage, 35)
Dim contactRow = New NTableRow()
Dim brandCell = New NTableCell With {
.Padding = New NMargins(5)
}
Dim brandParagraph = New NParagraph With {
.HorizontalAlignment = ENAlign.Left,
.Margins = New NMargins(0, 0, 0, 1)
}
brandParagraph.Inlines.Add(New NTextInline(x.Supplier.Name) With {
.FontSize = 15,
.FontStyle = ENFontStyle.Bold
})
brandCell.Blocks.Add(brandParagraph)
Dim sloganParagraph = New NParagraph With {
.HorizontalAlignment = ENAlign.Left,
.Margins = New NMargins(0, 0, 0, 1)
}
sloganParagraph.Inlines.Add(New NTextInline("Global expertise, local outcomes") With {
.FontSize = 15,
.FontStyle = ENFontStyle.Bold
})
brandCell.Blocks.Add(sloganParagraph)
contactRow.Cells.Add(brandCell)
Dim contactCell = New NTableCell With {
.Padding = New NMargins(5)
}
Dim emailParagraph = New NParagraph With {
.HorizontalAlignment = ENAlign.Right,
.Margins = New NMargins(0, 0, 0, 1)
}
emailParagraph.Inlines.Add(New NTextInline(x.Supplier.Email) With {
.FontSize = 10,
.FontStyle = ENFontStyle.Regular
})
contactCell.Blocks.Add(emailParagraph)
Dim websiteParagraph = New NParagraph With {
.HorizontalAlignment = ENAlign.Right,
.Margins = New NMargins(0, 0, 0, 1)
}
websiteParagraph.Inlines.Add(New NTextInline(x.Supplier.Website) With {
.FontSize = 10,
.FontStyle = ENFontStyle.Regular
})
contactCell.Blocks.Add(websiteParagraph)
contactRow.Cells.Add(contactCell)
contact.Rows.Add(contactRow)
section.Blocks.Add(contact)
section.Blocks.Add(New NParagraph With {
.Margins = New NMargins(0, 0, 0, 14)
})
Dim parties = New NTable(0, 2) With {
.Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
}
Dim partiesRow = New NTableRow()
Dim partyValues = {x.Customer, x.Supplier}
Dim captions = {"CUSTOMER:", "SUPPLIER:"}
Dim alignments = {ENAlign.Left, ENAlign.Right}
For i = 0 To partyValues.Length - 1
Dim party = partyValues(i)
Dim alignment = alignments(i)
Dim partyCell = New NTableCell With {
.Padding = New NMargins(5)
}
Dim lines = {captions(i), party.Name, party.Address1, party.Address2, party.Country, $"EIN: {party.Ein}"}
For lineIndex = 0 To lines.Length - 1
Dim paragraph = New NParagraph With {
.HorizontalAlignment = alignment,
.Margins = New NMargins(0, 0, 0, 1)
}
paragraph.Inlines.Add(New NTextInline(lines(lineIndex)) With {
.FontSize = 10,
.FontStyle = If(lineIndex < 2, ENFontStyle.Bold, ENFontStyle.Regular)
})
partyCell.Blocks.Add(paragraph)
Next
partiesRow.Cells.Add(partyCell)
Next
parties.Rows.Add(partiesRow)
section.Blocks.Add(parties)
section.Blocks.Add(New NParagraph With {
.Margins = New NMargins(0, 0, 0, 16)
})
End Sub
' SECTION 2 - invoice title, dates and reference
Private Shared Sub AddInvoiceIdentity(section As NSection, x As InvoiceData)
Dim title = New NParagraph With {
.HorizontalAlignment = ENAlign.Center,
.Margins = New NMargins(0, 0, 0, 1)
}
title.Inlines.Add(New NTextInline("INVOICE") With {
.FontSize = 24,
.FontStyle = ENFontStyle.Bold
})
section.Blocks.Add(title)
Dim original = New NParagraph With {
.HorizontalAlignment = ENAlign.Center,
.Margins = New NMargins(0, 0, 0, 1)
}
original.Inlines.Add(New NTextInline("ORIGINAL") With {
.FontSize = 16,
.FontStyle = ENFontStyle.Bold
})
section.Blocks.Add(original)
Dim number = New NParagraph With {
.HorizontalAlignment = ENAlign.Center,
.Margins = New NMargins(0, 0, 0, 1)
}
number.Inlines.Add(New NTextInline($"No. {x.Number} / {x.IssueDate:dd.MM.yyyy}") With {
.FontSize = 12,
.FontStyle = ENFontStyle.Bold
})
section.Blocks.Add(number)
Dim metadata = New NTable(0, 3) With {
.Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
}
Dim metadataRow = New NTableRow()
Dim metadataValues = {$"Tax point date: {x.TaxPointDate:dd.MM.yyyy}", $"Due date: {x.DueDate:dd.MM.yyyy}", $"Customer reference: {x.CustomerReference}"}
Dim metadataAlignments = {ENAlign.Left, ENAlign.Center, ENAlign.Right}
For i = 0 To metadataValues.Length - 1
Dim cell = New NTableCell With {
.Padding = New NMargins(5)
}
Dim paragraph = New NParagraph With {
.HorizontalAlignment = metadataAlignments(i),
.Margins = New NMargins(0, 0, 0, 1)
}
paragraph.Inlines.Add(New NTextInline(metadataValues(i)) With {
.FontSize = 10,
.FontStyle = ENFontStyle.Bold
})
cell.Blocks.Add(paragraph)
metadataRow.Cells.Add(cell)
Next
metadata.Rows.Add(metadataRow)
section.Blocks.Add(metadata)
section.Blocks.Add(New NParagraph With {
.Margins = New NMargins(0, 0, 0, 8)
})
End Sub
' SECTION 3 - line-item table
Private Shared Sub AddLineItems(section As NSection, x As InvoiceData)
Dim table = New NTable(0, 6) With {
.Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
}
Dim widths As Double() = {4, 49, 8, 9, 15, 15}
For i = 0 To widths.Length - 1
table.Columns(i).PreferredWidth = New NMultiLength(ENMultiLengthUnit.Percentage, widths(i))
Next
Dim headerRow = New NTableRow()
Dim headers = {"No.", "Description of goods/services", "Qty", "Unit", "Unit price", "Amount"}
Dim headerAlignments = {ENAlign.Left, ENAlign.Left, ENAlign.Right, ENAlign.Left, ENAlign.Right, ENAlign.Right}
For i = 0 To headers.Length - 1
Dim cell = New NTableCell With {
.Padding = New NMargins(5),
.BackgroundFill = New NColorFill(HeaderGray)
}
Dim paragraph = New NParagraph With {
.HorizontalAlignment = headerAlignments(i),
.Margins = New NMargins(0, 0, 0, 1)
}
paragraph.Inlines.Add(New NTextInline(headers(i)) With {
.FontSize = 10,
.FontStyle = ENFontStyle.Bold
})
cell.Blocks.Add(paragraph)
headerRow.Cells.Add(cell)
Next
table.Rows.Add(headerRow)
For lineIndex = 0 To x.Lines.Count - 1
Dim line = x.Lines(lineIndex)
Dim amount = line.Quantity * line.UnitPrice
Dim values = {(lineIndex + 1).ToString(En), $"{line.Code}
{line.Description}
{line.Period}", line.Quantity.ToString("N2", En), line.Unit, $"{line.UnitPrice.ToString("N2", En)} {x.Currency}", $"{amount.ToString("N2", En)} {x.Currency}"}
Dim alignments = {ENAlign.Left, ENAlign.Left, ENAlign.Right, ENAlign.Left, ENAlign.Right, ENAlign.Right}
Dim row = New NTableRow()
For columnIndex = 0 To values.Length - 1
Dim cell = New NTableCell With {
.Padding = New NMargins(5)
}
For Each textLine In values(columnIndex).Split(ChrW(10))
Dim paragraph = New NParagraph With {
.HorizontalAlignment = alignments(columnIndex),
.Margins = New NMargins(0, 0, 0, 1)
}
paragraph.Inlines.Add(New NTextInline(textLine) With {
.FontSize = 10,
.FontStyle = ENFontStyle.Regular
})
cell.Blocks.Add(paragraph)
Next
row.Cells.Add(cell)
Next
table.Rows.Add(row)
Next
section.Blocks.Add(table)
section.Blocks.Add(New NParagraph With {
.Margins = New NMargins(0, 0, 0, 8)
})
End Sub
' SECTION 4 - subtotal, optional sales tax and total
Private Shared Sub AddTotals(section As NSection, x As InvoiceData)
Dim net As Decimal = 0
For Each line In x.Lines
net += line.Quantity * line.UnitPrice
Next
Dim salesTax = Math.Round(net * x.SalesTaxRate, 2)
Dim gross = net + salesTax
Dim outer = New NTable(0, 2) With {
.Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
}
outer.Columns(0).PreferredWidth = New NMultiLength(ENMultiLengthUnit.Percentage, 52)
outer.Columns(1).PreferredWidth = New NMultiLength(ENMultiLengthUnit.Percentage, 48)
Dim outerRow = New NTableRow()
Dim emptyCell = New NTableCell With {
.Padding = New NMargins(5)
}
Dim emptyParagraph = New NParagraph With {
.HorizontalAlignment = ENAlign.Left,
.Margins = New NMargins(0, 0, 0, 1)
}
emptyParagraph.Inlines.Add(New NTextInline(String.Empty) With {
.FontSize = 10,
.FontStyle = ENFontStyle.Regular
})
emptyCell.Blocks.Add(emptyParagraph)
outerRow.Cells.Add(emptyCell)
Dim totalsCell = New NTableCell()
Dim totals = New NTable(0, 3) With {
.Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
}
Dim totalRows = New List(Of TotalRow) From {
New TotalRow("Invoice subtotal:", $"{net.ToString("N2", En)} {x.Currency}", $"{net.ToString("N2", En)} {x.Currency}", False)
}
If x.SalesTaxRate > 0 Then
totalRows.Add(New TotalRow("Sales tax rate:", x.SalesTaxRate.ToString("P2", En), String.Empty, False))
totalRows.Add(New TotalRow("Sales tax:", $"{salesTax.ToString("N2", En)} {x.Currency}", $"{salesTax.ToString("N2", En)} {x.Currency}", False))
End If
totalRows.Add(New TotalRow("TOTAL:", $"{gross.ToString("N2", En)} {x.Currency}", $"{gross.ToString("N2", En)} {x.Currency}", True))
For Each totalRow In totalRows
Dim label = totalRow.Label
Dim middle = totalRow.Middle
Dim strong = totalRow.Strong
Dim bold = totalRow.Bold
Dim row = New NTableRow()
Dim values = {label, middle, strong}
For i = 0 To values.Length - 1
Dim cell = New NTableCell With {
.Padding = New NMargins(5)
}
If i = 2 AndAlso values(i).Length > 0 Then
cell.BackgroundFill = New NColorFill(HeaderGray)
End If
Dim paragraph = New NParagraph With {
.HorizontalAlignment = ENAlign.Right,
.Margins = New NMargins(0, 0, 0, 1)
}
paragraph.Inlines.Add(New NTextInline(values(i)) With {
.FontSize = 10,
.FontStyle = If(bold OrElse i = 2, ENFontStyle.Bold, ENFontStyle.Regular)
})
cell.Blocks.Add(paragraph)
row.Cells.Add(cell)
Next
totals.Rows.Add(row)
Next
totalsCell.Blocks.Add(totals)
outerRow.Cells.Add(totalsCell)
outer.Rows.Add(outerRow)
section.Blocks.Add(outer)
section.Blocks.Add(New NParagraph With {
.Margins = New NMargins(0, 0, 0, 22)
})
End Sub
' SECTION 5 - bank details, payment summary and QR widget
Private Shared Sub AddPaymentSection(section As NSection, x As InvoiceData)
Dim net As Decimal = 0
For Each line In x.Lines
net += line.Quantity * line.UnitPrice
Next
Dim salesTax = Math.Round(net * x.SalesTaxRate, 2, MidpointRounding.AwayFromZero)
Dim total = net + salesTax
Dim table = New NTable(0, 3) With {
.Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
}
table.Columns(0).PreferredWidth = New NMultiLength(ENMultiLengthUnit.Percentage, 53)
table.Columns(1).PreferredWidth = New NMultiLength(ENMultiLengthUnit.Percentage, 27)
table.Columns(2).PreferredWidth = New NMultiLength(ENMultiLengthUnit.Percentage, 20)
Dim row = New NTableRow()
Dim bankCell = New NTableCell With {
.Padding = New NMargins(5)
}
Dim bankLines = {"BANK DETAILS:", x.BankName, $"ABA routing number: {x.RoutingNumber}", $"Account number: {x.AccountNumber}", $"Account type: {x.AccountType}"}
For i = 0 To bankLines.Length - 1
Dim paragraph = New NParagraph With {
.HorizontalAlignment = ENAlign.Left,
.Margins = New NMargins(0, 0, 0, 1)
}
paragraph.Inlines.Add(New NTextInline(bankLines(i)) With {
.FontSize = If(i = 1, 12, 10),
.FontStyle = If(i < 2, ENFontStyle.Bold, ENFontStyle.Regular)
})
bankCell.Blocks.Add(paragraph)
Next
row.Cells.Add(bankCell)
Dim detailsCell = New NTableCell With {
.Padding = New NMargins(5)
}
Dim detailLines = {$"Amount due: {total.ToString("N2", En)} {x.Currency}", "Exchange rate: 1.00000", $"Prepared by: {x.PreparedBy}", "Scan to pay:"}
For i = 0 To detailLines.Length - 1
Dim paragraph = New NParagraph With {
.HorizontalAlignment = ENAlign.Left,
.Margins = New NMargins(0, 0, 0, 1)
}
paragraph.Inlines.Add(New NTextInline(detailLines(i)) With {
.FontSize = 10,
.FontStyle = If(i = 0 OrElse i = 3, ENFontStyle.Bold, ENFontStyle.Regular)
})
detailsCell.Blocks.Add(paragraph)
Next
row.Cells.Add(detailsCell)
Dim qrCell = New NTableCell With {
.Padding = New NMargins(5)
}
Dim qrParagraph = New NParagraph With {
.HorizontalAlignment = ENAlign.Center,
.Margins = New NMargins(0, 0, 0, 1)
}
Dim qr = New NMatrixBarcode(ENMatrixBarcodeSymbology.QrCode, x.PaymentUrl) With {
.ErrorCorrection = ENErrorCorrectionLevel.Medium,
.PreferredSize = New NSize(92, 92)
}
qrParagraph.Inlines.Add(New NWidgetInline(qr))
qrCell.Blocks.Add(qrParagraph)
Dim qrCaption = New NParagraph With {
.HorizontalAlignment = ENAlign.Center,
.Margins = New NMargins(0, 0, 0, 1)
}
qrCaption.Inlines.Add(New NTextInline("Imaginary payment link") With {
.FontSize = 8,
.FontStyle = ENFontStyle.Regular
})
qrCell.Blocks.Add(qrCaption)
row.Cells.Add(qrCell)
table.Rows.Add(row)
section.Blocks.Add(table)
End Sub
'''
''' Header
'''
'''
Private Shared Sub AddHeader(section As NSection, supplier As Party)
Dim header As NHeaderFooter = New NHeaderFooter()
header.Blocks.Add(New NParagraph(supplier.Name))
section.Header = header
End Sub
' SECTION 6 - repeating page footer
Private Shared Sub AddFooter(section As NSection)
Dim footer = New NHeaderFooter()
Dim table = New NTable(0, 2) With {
.Border = NBorder.CreateFilledBorder(NColor.LightGray, 0.5, 0.5)
}
Dim row = New NTableRow()
Dim noticeCell = New NTableCell With {
.Padding = New NMargins(5)
}
Dim noticeParagraph = New NParagraph With {
.HorizontalAlignment = ENAlign.Left,
.Margins = New NMargins(0, 0, 0, 1)
}
noticeParagraph.Inlines.Add(New NTextInline("This invoice was generated electronically and is valid without a signature.") With {
.FontSize = 8,
.FontStyle = ENFontStyle.Regular
})
noticeCell.Blocks.Add(noticeParagraph)
row.Cells.Add(noticeCell)
Dim pageCell = New NTableCell With {
.Padding = New NMargins(5)
}
Dim pageParagraph = New NParagraph With {
.HorizontalAlignment = ENAlign.Right,
.Margins = New NMargins(0, 0, 0, 1)
}
pageParagraph.Inlines.Add(New NTextInline("1/1") With {
.FontSize = 8,
.FontStyle = ENFontStyle.Regular
})
pageCell.Blocks.Add(pageParagraph)
row.Cells.Add(pageCell)
table.Rows.Add(row)
footer.Blocks.Add(table)
section.Footer = footer
End Sub
#End Region
#Region "Event Handlers"
#End Region
#Region "Fields"
Private m_RichText As NRichTextView
Private Shared ReadOnly En As CultureInfo = CultureInfo.GetCultureInfo("en-GB")
Private Shared ReadOnly HeaderGray As NColor = NColor.FromRGB(225, 225, 225)
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
Private NotInheritable Class Party
Public Sub New(name As String, address1 As String, address2 As String, country As String, ein As String, email As String, website As String)
Me.Name = name
Me.Address1 = address1
Me.Address2 = address2
Me.Country = country
Me.Ein = ein
Me.Email = email
Me.Website = website
End Sub
Public ReadOnly Name As String
Public ReadOnly Address1 As String
Public ReadOnly Address2 As String
Public ReadOnly Country As String
Public ReadOnly Ein As String
Public ReadOnly Email As String
Public ReadOnly Website As String
End Class
Private NotInheritable Class InvoiceLine
Public Sub New(code As String, description As String, period As String, quantity As Decimal, unit As String, unitPrice As Decimal)
Me.Code = code
Me.Description = description
Me.Period = period
Me.Quantity = quantity
Me.Unit = unit
Me.UnitPrice = unitPrice
End Sub
Public ReadOnly Code As String
Public ReadOnly Description As String
Public ReadOnly Period As String
Public ReadOnly Quantity As Decimal
Public ReadOnly Unit As String
Public ReadOnly UnitPrice As Decimal
End Class
Private NotInheritable Class InvoiceData
Public Sub New(number As String, issueDate As Date, taxPointDate As Date, dueDate As Date, customerReference As String, customer As Party, supplier As Party, lines As IList(Of InvoiceLine), salesTaxRate As Decimal, currency As String, bankName As String, routingNumber As String, accountNumber As String, accountType As String, preparedBy As String, paymentUrl As String)
Me.Number = number
Me.IssueDate = issueDate
Me.TaxPointDate = taxPointDate
Me.DueDate = dueDate
Me.CustomerReference = customerReference
Me.Customer = customer
Me.Supplier = supplier
Me.Lines = lines
Me.SalesTaxRate = salesTaxRate
Me.Currency = currency
Me.BankName = bankName
Me.RoutingNumber = routingNumber
Me.AccountNumber = accountNumber
Me.AccountType = accountType
Me.PreparedBy = preparedBy
Me.PaymentUrl = paymentUrl
End Sub
Public ReadOnly Number As String
Public ReadOnly IssueDate As Date
Public ReadOnly TaxPointDate As Date
Public ReadOnly DueDate As Date
Public ReadOnly CustomerReference As String
Public ReadOnly Customer As Party
Public ReadOnly Supplier As Party
Public ReadOnly Lines As IList(Of InvoiceLine)
Public ReadOnly SalesTaxRate As Decimal
Public ReadOnly Currency As String
Public ReadOnly BankName As String
Public ReadOnly RoutingNumber As String
Public ReadOnly AccountNumber As String
Public ReadOnly AccountType As String
Public ReadOnly PreparedBy As String
Public ReadOnly PaymentUrl As String
End Class
Private NotInheritable Class TotalRow
Public Sub New(label As String, middle As String, strong As String, bold As Boolean)
Me.Label = label
Me.Middle = middle
Me.Strong = strong
Me.Bold = bold
End Sub
Public ReadOnly Label As String
Public ReadOnly Middle As String
Public ReadOnly Strong As String
Public ReadOnly Bold As Boolean
End Class
#End Region
End Class