# 서식 JSON

> 용지, 라벨 크기, 요소 목록. 모든 길이는 mm 입니다.

Source: https://82label.app/docs/template/

서식은 JSON 하나입니다. 디자이너, 라이브러리, 출력 프로그램이 모두 이 형식만 씁니다. 좌표와 크기는 라벨 왼쪽 위를 0 으로 하는 **mm**, 글자 크기만 **pt** 입니다. 요소는 적힌 순서대로 그려집니다(뒤에 적은 것이 위).

```js
const template = {
  v: 1,
  name: '출고 라벨',
  paper: { kind: 'roll', dpi: 203 },
  label: { width: 60, height: 40 },
  elements: [
    { type: 'rect', x: 1, y: 1, w: 58, h: 38, stroke: 0.3, radius: 2 },
    { type: 'text', x: 4, y: 3, w: 36, h: 6, text: '{{orderNo}}', size: 9, bold: true },
    { type: 'text', x: 4, y: 10, w: 36, h: 12, text: '{{items}}', size: 8, fit: 'wrap' },
    { type: 'line', x1: 4, y1: 24, x2: 56, y2: 24, width: 0.3 },
    { type: 'text', x: 4, y: 26, w: 36, h: 10, text: '{{customer}}', size: 11, bold: true, valign: 'middle', fit: 'shrink' },
    { type: 'qr', x: 41, y: 4, size: 16, value: '{{orderUrl}}' },
  ],
  fields: [
    { name: 'orderNo', label: '주문번호', example: 'A-20261022-0012' },
    { name: 'items', label: '품목', example: '무선 이어폰 프로 외 2건' },
    { name: 'customer', label: '고객', example: '김하늘' },
    { name: 'orderUrl', label: 'URL', example: 'https://shop.example.com/o/12' },
  ],
};

Label82.print(template);
```

## 맨 위 항목

| 항목 | 설명 |
| --- | --- |
| `v` | 형식 버전. 지금은 `1`. |
| `name` | 서식 이름(내 서식 목록, 인쇄 기록에 보입니다). |
| `paper` | `{ kind: 'roll' }` 또는 `{ kind: 'sheet', … }`. [롤 라벨](https://82label.app/docs/roll/), [폼텍 시트](https://82label.app/docs/sheets/) 참고. |
| `label` | 라벨 한 장(시트는 한 칸)의 `width`, `height`, 둥근 모서리 `radius`. |
| `elements` | 요소 목록. 아래 표. |
| `fields` | 선택. `{ name, label, example }` 목록. 디자이너 미리보기와 예시값에 씁니다. |

## 요소

| type | 꼭 필요한 값 | 선택 |
| --- | --- | --- |
| `text` | `x y w h text size` | `bold`, `align`(left·center·right), `valign`(top·middle·bottom), `fit`(shrink·wrap·clip), `font`, `rotate`(0·90·180·270). `size` 는 pt. |
| `barcode` | `value` | `x y w h`(빼면 가운데, 너비 80%), `format`(기본 code128), `showText`, `codeSet`, `rotate` |
| `qr` | `value` | `x y size`(빼면 가운데 정사각형), `ecc`(L·M·Q·H, 기본 M) |
| `image` | `x y w h src` | `src` 는 data: URL, https 주소 또는 `{{필드}}`. `fit`(contain·cover) |
| `line` | `x1 y1 x2 y2 width` | 선 두께 `width` 는 mm |
| `rect` | `x y w h` | `stroke`(테두리 두께 mm, 기본 0.3, 0 이면 없음), `fill`(none·black), `radius` |

## 흑백만

라벨프린터는 대부분 감열(흑백)이라 색은 없습니다. 검은 바탕에 흰 글자가 필요하면 `fill: 'black'` 박스 위에 글자를 두지 말고 이미지를 쓰세요.

## 미리 인쇄된 틀 (layer: 'frame')

칸 선, "받는 분" 같은 이름표처럼 용지에 이미 인쇄된 부분은 `layer: 'frame'` 을 붙입니다. 화면과 빈 용지에는 그리고, 틀이 인쇄된 용지에 찍을 때는 `print(t, rows, { frames: false })` 로 빼고 값만 찍습니다.

> 서식 JSON 의 JSON Schema: [/schema/template.json](https://82label.app/schema/template.json). 서버(82label.app)는 저장할 때 `v`, 용지 종류, 라벨 크기, 요소 개수(최대 2,000)만 확인합니다.
