Menu

How to Generate Official Saudi ZATCA Phase-1 TLV QR Codes in Pure TypeScript (Fixing the Arabic UTF-8 Bug)
📰

How to Generate Official Saudi ZATCA Phase-1 TLV QR Codes in Pure TypeScript (Fixing the Arabic UTF-8 Bug)

DEV Community: nextjs·Andrew Zachary·8 days ago
#46vteo9L
#devtonextjs#devto#dev#length#string
Long article (495 words) — no AI summary yet.
Reading 0:00
15s threshold

If you have ever built an e-invoicing app for Saudi Arabia (KSA), you know ZATCA Phase-1 (Fatoora) requires every simplified tax invoice to carry a Base64-encoded TLV (Tag-Length-Value) QR code with 5 fields:

Tag 1: Seller Name

Tag 2: Seller VAT Registration Number (15 digits)

Tag 3: Invoice Timestamp (ISO 8601)

Tag 4: Invoice Grand Total (including VAT)

Tag 5: VAT Total Amount

The #1 Bug That Breaks Arabic Seller Names

Many quick JS snippets use string.length as the TLV Length byte:

// BROKEN FOR ARABIC TEXT: "شركة" has length 4, but is 8 UTF-8 bytes! const badLength = sellerName . length ;

Enter fullscreen mode

Exit fullscreen mode

ZATCA's Fatoora QR scanner validates exact UTF-8 byte lengths , not UTF-16 code units.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.