ESC/POS Receipt Generator (Vietnamese-safe) API
Turn a receipt (items, totals, QR, barcode) into ESC/POS bytes for 58 / 80 mm thermal printers, with Vietnamese printed as an image and a PNG preview.
Describe the receipt as blocks (text with align / bold / size / underline / invert, row with left and right text, divider, feed, qr, barcode (Code 128, EAN-13, Code 39), image (PNG / JPEG, dithered)) or as a simple receipt object (store, header, title, info, items with name / qty / price, discount, vat, total, paid, qr, footer) and get the ESC/POS byte stream (base64) plus a PNG preview of exactly what will print.
Thermal printers sold in Vietnam often have no Vietnamese code page, so mode=raster (default) draws all text with the Be Vietnam Pro font and sends the receipt as a GS v 0 bit image: diacritics print correctly on any ESC/POS printer. mode=tcvn3 sends native text in the TCVN-3 code page (ESC t 30, Epson-compatible printers; faster, but toned capitals are missing), mode=ascii removes diacritics. In the text modes QR codes and barcodes use the printer’s own commands. cut (default on) adds a partial cut, open_drawer=true kicks the cash drawer.
APIBox cannot reach a printer on your network: send the bytes yourself through WebUSB, Web Bluetooth, a TCP socket to port 9100, or the RawBT app on Android. format=bin returns the raw bytes, format=png the preview only.
Markdown · OpenAPI · Postman · llms.txt
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
receipt | body | object | no | Simple receipt: store, header, title, info, items [{name, qty, price}], discount, vat, total, paid, qr, qr_caption, barcode, footer, currency. | |
blocks | body | array | no | Layout blocks: text, row, divider, feed, qr, barcode, image (max 500). | |
paper | body | string | no | 80 | 58 or 80 (mm). |
mode | body | string | no | raster | raster (text as image, any printer), tcvn3 (code page 30) or ascii (no diacritics). |
cut | body | boolean | no | true | Partial cut at the end. |
open_drawer | body | boolean | no | false | Kick the cash drawer. |
format | body | string | no | json | json (base64 + preview), bin (raw bytes) or png (preview). |
Example
curl -X POST "https://apibox.io.vn/v1/escpos-receipt" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"paper":"58","receipt":{"store":"Quán Cà Phê","items":[{"name":"Cà phê sữa đá","qty":2,"price":29000}],"paid":100000,"footer":"Cảm ơn quý khách!"}}'const res = await fetch('https://apibox.io.vn/v1/escpos-receipt', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"paper": "58",
"receipt": {
"store": "Quán Cà Phê",
"items": [
{
"name": "Cà phê sữa đá",
"qty": 2,
"price": 29000
}
],
"paid": 100000,
"footer": "Cảm ơn quý khách!"
}
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/escpos-receipt",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"paper": "58", "receipt": {"store": "Quán Cà Phê", "items": [{"name": "Cà phê sữa đá", "qty": 2, "price": 29000}], "paid": 100000, "footer": "Cảm ơn quý khách!"}},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/escpos-receipt');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"paper":"58","receipt":{"store":"Quán Cà Phê","items":[{"name":"Cà phê sữa đá","qty":2,"price":29000}],"paid":100000,"footer":"Cảm ơn quý khách!"}}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"paper_mm": 58,
"mode": "raster",
"width_dots": 384,
"height_dots": 318,
"length_mm": 39.8,
"bytes": 15289,
"escpos_base64": "G0AddjAAMAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA…",
"preview_png": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYAAAAE+CAAAAA…",
"warnings": [],
"notes": "Raster mode (GS v 0) prints Vietnamese on any ESC/POS printer."
}
Use cases
- Print receipts with correct Vietnamese from a web POS through WebUSB
- Generate kitchen / bar tickets from Google Sheets or AppSheet orders
- Add a VietQR payment code to receipts printed by a Flutter app
- Preview receipt layouts before sending them to a printer
FAQ
Why does Vietnamese print as question marks on my printer?
The printer has no Vietnamese code page. Use mode=raster (the default): the text is printed as an image, which every ESC/POS printer supports.
Which printers are supported?
Any ESC/POS-compatible 58 mm (384 dots) or 80 mm (576 dots) printer, e.g. Epson TM, Xprinter, Gprinter, Rongta, Sunmi.
Can APIBox print directly?
No, a cloud API cannot reach your LAN or USB. Send the returned bytes to the printer from your app, browser or a print relay.
Related APIs
QR Code Generator
Generate QR codes as PNG or SVG with one GET request: URLs, text, WiFi logins, vCards, e-mail, SMS, phone and geo links. Custom colours, size and ECC.
|||Barcode Generator
Create Code 128 barcodes for labels, SKUs and shipping with a single request. SVG with human-readable text or PNG, custom height, width and colours.
▭Placeholder Image
Get placeholder images of any size for mockups and tests: /v1/placeholder/600x400.png. SVG with custom text and colours, or a solid-colour PNG.