Skip to content

Commit 54f0351

Browse files
committed
Update docs
1 parent c02d024 commit 54f0351

3 files changed

Lines changed: 66 additions & 75 deletions

File tree

docs/wiki/Cookbook.md

Lines changed: 66 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,39 @@ flexrender render table-receipt.yaml -d invoice-data.json -o invoice.jpg --quali
463463

464464
### Receipt with NDC Content
465465

466-
NDC (NCR Direct Connect) is a binary protocol used by ATM terminals to format printer output. The `content` element with `format: ndc` parses these binary data streams into FlexRender elements. This is useful when rendering ATM receipt images from raw transaction data captured by banking middleware.
466+
NDC (NCR Direct Connect) is a protocol used by ATM terminals to format printer output. The `content` element with `format: ndc` parses NDC data streams into FlexRender elements. This is useful when rendering ATM receipt images from raw transaction data captured by banking middleware.
467467

468468
The NDC parser requires `FlexRender.Content.Ndc` and `.WithNdc()` on the builder. A monospaced font (such as JetBrains Mono or Courier) is recommended for accurate column alignment.
469469

470-
**Template:**
470+
The simplest approach is to reference the NDC data file directly in the template using `file:` source. NDC data files are typically `.bin` files containing escape sequences (`ESC` = `0x1B`) for charset switching, text formatting, and layout control.
471+
472+
**NDC data file** (`ndc-data/receipt.bin`):
473+
474+
The file contains raw NDC escape sequences. When viewed in a text editor, it looks like this (escape characters shown as `ESC`):
475+
476+
```
477+
ESC(2 ESC(I г. москва, ESC(I ул. тестовая, д. 1, корп. 1 Б
478+
479+
ESC(IД ESC(Jата ESC(IВ ESC(Jремя ESC(IБ ESC(Jанкомат
480+
01.01.25 10:00:00 ATM00004
481+
482+
ESC(IК ESC(Jарта: ESC(2 4..0000(Our TESTCARD)
483+
AID: A0000000000000 TESTCARD DEBIT
484+
TVR: 0000000000
485+
ESC(IК ESC(Jод операции: 000000/000000000000
486+
487+
ESC(I"И ESC(Jнформация о Балансе"
488+
489+
ESC(IВ ESC(Jсего доступно:
490+
+12345.67 RUR
491+
ESC(Jиз них:
492+
доступный кредитный лимит:
493+
+0.00 RUB
494+
```
495+
496+
The charset designators (`I`, `J`, `2`) control text styling — bold, Cyrillic encoding, and default font respectively.
497+
498+
**Template** (`ndc-receipt.yaml`):
471499

472500
```yaml
473501
fonts:
@@ -480,94 +508,63 @@ canvas:
480508
background: "#ffffff"
481509

482510
layout:
483-
# Bank header (static)
484-
- type: flex
485-
padding: "16 20"
486-
gap: 4
487-
align: center
488-
children:
489-
- type: text
490-
content: "{{bankName}}"
491-
fontWeight: bold
492-
size: 1.2em
493-
align: center
494-
- type: text
495-
content: "ATM #{{atmId}}"
496-
size: 0.8em
497-
color: "#666666"
498-
align: center
499-
500-
- type: separator
501-
style: solid
502-
color: "#cccccc"
503-
504-
# NDC receipt body (parsed from binary data)
505511
- type: content
506-
source: "{{receiptData}}"
512+
source: "file:ndc-data/receipt.bin"
507513
format: ndc
508514
options:
509515
columns: 40
510-
input_encoding: latin1
511-
font_family: "JetBrains Mono"
516+
font_family: JetBrains Mono
512517
charsets:
513-
"1":
514-
encoding: "qwerty-jcuken"
515-
font_style: bold
516-
"I":
518+
I:
517519
font: bold
520+
font_style: bold
521+
encoding: qwerty-jcuken
518522
uppercase: true
523+
J:
524+
encoding: qwerty-jcuken
525+
"2":
526+
font: default
527+
```
519528
520-
- type: separator
521-
style: solid
522-
color: "#cccccc"
529+
**CLI:**
523530
524-
# Footer (static)
525-
- type: flex
526-
padding: "12 20"
527-
gap: 2
528-
children:
529-
- type: text
530-
content: "{{date}}"
531-
size: 0.75em
532-
align: center
533-
color: "#999999"
534-
- type: text
535-
content: "Please retain this receipt"
536-
size: 0.75em
537-
align: center
538-
color: "#999999"
531+
```bash
532+
flexrender render ndc-receipt.yaml -o receipt.png
533+
534+
# For thermal printer (monochrome BMP)
535+
flexrender render ndc-receipt.yaml -o receipt.bmp --bmp-color monochrome1
539536
```
540537

541-
**Data (C#):**
538+
**How it works:**
542539

543-
```csharp
544-
var data = new ObjectValue
545-
{
546-
["bankName"] = "First National Bank",
547-
["atmId"] = "ATM-0042",
548-
["receiptData"] = new BytesValue(ndcBinaryBytes),
549-
["date"] = "2026-03-08 09:15:33"
550-
};
551-
```
540+
- `source: "file:ndc-data/receipt.bin"` — loads the NDC data from a local file relative to the template location
541+
- `columns: 40` — receipt width in characters (standard for 80mm thermal printers)
542+
- `charsets` — defines styling for each charset designator in the NDC stream:
543+
- `I` — bold Cyrillic text (QWERTY-JCUKEN encoding, uppercased)
544+
- `J` — regular Cyrillic text (QWERTY-JCUKEN encoding)
545+
- `2` — default Latin font (digits, punctuation, card numbers)
546+
- The parser automatically handles line wrapping, charset switching (`ESC(X` sequences), and spacing control codes
552547

553-
**Builder setup:**
548+
**C# API** (for programmatic use):
554549

555550
```csharp
556551
var render = new FlexRenderBuilder()
557552
.WithNdc()
558553
.WithSkia()
559554
.Build();
555+
556+
// Load NDC data from file
557+
var ndcBytes = File.ReadAllBytes("ndc-data/receipt.bin");
558+
559+
var data = new ObjectValue
560+
{
561+
["receiptData"] = new BytesValue(ndcBytes)
562+
};
560563
```
561564

562-
> **Note:** NDC receipts use binary data (`BytesValue`), so they must be rendered through the C# API. The CLI does not support binary data inputs. For text-based NDC content, you can use `data:` URI format in the JSON data:
563-
>
564-
> ```json
565-
> { "receiptData": "data:application/octet-stream;base64,PFN0YXJ0PjxOREMgZGF0YT4..." }
566-
> ```
567-
>
568-
> ```bash
569-
> flexrender render ndc-receipt.yaml -d ndc-data.json -o atm-receipt.png
570-
> ```
565+
With the C# API, you can also pass NDC data dynamically via template variables (`source: "{{receiptData}}"`) using `BytesValue` for binary data or `StringValue` for text data.
566+
567+
> **Tip:** Use `flexrender debug-layout ndc-receipt.yaml` to visualize element boundaries and debug charset switching issues.
571568
572569
---
573570

examples/output/psb-balance.png

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/output/psb.png

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)