362 Template: Customer welcome letter

Customer welcome letter

Type on the left - the preview on the right updates with real data from the chosen record. Click a field in the list to insert it at the cursor.

← All templates

Syntax

# Title / ## HeadingLarge title / blue sub heading
**bold words**Bold text - a whole line or just some words
^ text / > textCentred / right-aligned line
---Horizontal line
| A | B |Table row - the first row is the header
{{customer.name}}Data field (list on the right)
[[lines]] [[totals]]Invoice line table / totals (INVOICE source)
[[barcode:TEXT]] [[qr:TEXT]]Code 128 / QR code - TEXT may contain fields
[[signature:Name|Role]]Signature line
[[pagebreak]]Start a new page
Print PDF (saved version)

Welcome, Andaman Dive Resort

Bangkok, 9 November 2026

Dear Mr. Daniel Hart,

Thank you for choosing Northwind Print Co., Ltd. - your customer code is C-1003. Please quote it on every order.


Your account

FieldValue
Customer codeC-1003
Tax ID0835554567890
E-mailoffice@andamandive.example
Phone+66 76 555 303
Address9 Moo 3, Karon Beach, Mueang, Phuket 83100

Scan to save our contact e-mail:

QR code

We look forward to working with you.

Customer Service Team
Northwind Print Co., Ltd.

Fields for CUSTOMER

{{company.name}}Northwind Print Co., Ltd.
{{company.address}}88 Rama VI Road, Ratchathewi, Bangkok 10400
{{company.taxId}}0105559999999
{{company.phone}}+66 2 123 4567
{{today}}9 November 2026
{{customer.code}}C-1003
{{customer.name}}Andaman Dive Resort
{{customer.contact}}Mr. Daniel Hart
{{customer.email}}office@andamandive.example
{{customer.phone}}+66 76 555 303
{{customer.address}}9 Moo 3, Karon Beach, Mueang, Phuket 83100
{{customer.taxId}}0835554567890
{{record.label}}C-1003
How it works
  1. DocTemplateEngine.parse(body) turns each line into a block: Heading, Text, TableBlock, Tag ... (Java 21 sealed interface + records).
  2. fill() replaces {{key}} with a regex; unknown keys show as [?key].
  3. The same blocks are rendered twice: toHtml() for this preview (a switch with pattern matching) and toPdf() with OpenPDF for printing.
  4. The data map is built from SQL Server in TemplateService.context().
for (Block b : blocks) {
    switch (b) {
        case Heading h  -> doc.add(para(fill(h.text(), ctx), Fonts.bold(18), ALIGN_LEFT, 6));
        case TableBlock t -> doc.add(tablePdf(t, ctx));
        case Tag t      -> tagPdf(doc, t, ctx, barcodes);   // [[lines]], [[qr:...]] ...
        ...
    }
}

Files: service/DocTemplateEngine.java, service/TemplateService.java, web/TemplateController.java.