# 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.

- Endpoint: `POST https://apibox.io.vn/v1/escpos-receipt`
- Category: Images & Codes
- HTML docs: https://apibox.io.vn/docs/escpos-receipt/ (Vietnamese: https://apibox.io.vn/vi/docs/escpos-receipt/)
- Online tool: https://apibox.io.vn/tools/escpos-receipt/
- Authentication: `Authorization: Bearer <API key>` or `X-API-Key: <API key>` (free key: https://apibox.io.vn/dashboard/#signup)

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.

## Parameters

| Name | In | Type | Required | Default | Description |
|---|---|---|---|---|---|
| `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 request

```bash
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!"}}'
```

## Example response

```json
{
  "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.
