MIT Open-Source JavaScript Implementation (Zero Dependencies)

Saudi Arabia's ZATCA (Fatoora) Phase-1 Simplified Tax Invoice specification requires a QR code containing 5 UTF-8 Tag-Length-Value (TLV) fields encoded in Base64. Common bugs occur when developers pass string.length instead of UTF-8 byteLength for Arabic seller names. The verified 15-line browser implementation below handles Arabic UTF-8 bytes natively with zero backend calls:

export function encodeZatcaPhase1TLV(seller, vatNumber, isoTimestamp, invoiceTotal, vatTotal) {
  const enc = new TextEncoder();
  const tags = [[1, seller], [2, vatNumber], [3, isoTimestamp], [4, invoiceTotal], [5, vatTotal]];
  const chunks = [];
  for (const [tag, val] of tags) {
    const bytes = enc.encode(String(val));
    chunks.push(tag, bytes.length, ...bytes);
  }
  return btoa(String.fromCharCode(...chunks));
}

Need a Ready-to-Print Arabic Tax Invoice with Live ZATCA QR?

Try our free, zero-signup Saudi ZATCA Phase-1 Invoice Generator โ€” it computes 15% VAT, encodes Arabic UTF-8 TLV bytes locally, renders a scannable SVG QR code, and exports clean A4 PDFs with zero server uploads.