CPCL Commands
CPCL (Comtec Printer Control Language) is a text-based command language for portable label printers.
Overview
Section titled “Overview”CPCL uses human-readable text. Each command consists of a command name and parameters separated by spaces.
Basic syntax
Section titled “Basic syntax”Command format
Section titled “Command format”Command name Parameters 1 Parameters 2 Parameters 3 ...String handling
Section titled “String handling”- Enclose strings in double quotes
" - Escape double quotes inside text as
["]
TEXT 4 0 100 100 "Hello World"TEXT 4 0 100 150 "Say ["]Hello["]"Character encoding
Section titled “Character encoding”Page setup commands
Section titled “Page setup commands”Create a page (!)
Section titled “Create a page (!)”Create a print page and set its dimensions and number of copies.
! offset horizontal_resolution vertical_resolution label_height number_of_copies| Parameter | Description | Units |
|---|---|---|
| Offset | Page offset | dot |
| Horizontal resolution | Printhead horizontal resolution | DPI |
| Vertical resolution | Printhead vertical resolution | DPI |
| Label height | Label height | dot |
| Number of copies | Number of copies | - |
Example:
! 0 200 200 400 1Page width (PAGE-WIDTH)
Section titled “Page width (PAGE-WIDTH)”Set the page width.
PAGE-WIDTH width| Parameter | Description | Units |
|---|---|---|
| Width | Page width | dot |
Example:
PAGE-WIDTH 576Print mode (FORM/FEED)
Section titled “Print mode (FORM/FEED)”Set the printer’s positioning mode.
FORMFORM- Advance to the next label (can be called after PRINT)FEED- Position at the label (must be called before PRINT)
Text printing commands
Section titled “Text printing commands”Text (TEXT/T)
Section titled “Text (TEXT/T)”Print text content.
TEXT font size X Y "content"T font size X Y "content"| Parameter | Description |
|---|---|
| Font | Font ID |
| Size | Font size |
| X | Text starting X coordinate (dot) |
| Y | Text starting Y coordinate (dot) |
| Content | Text to print |
Available fonts
Section titled “Available fonts”| Font enum | Font ID | Size | -dot matrix height |
|---|---|---|---|
| TSS16 | 55 | 0 | 16 |
| TSS20 | 6 | 0 | 20 |
| TSS24 | 24 | 0 | 24 |
| TSS28 | 7 | 0 | 28 |
| TSS32 | 4 | 0 | 32 |
Example:
TEXT 24 0 50 50 "产品名称"TEXT 7 0 50 100 "规格型号"T 4 0 50 150 "大号文字"Rotated text (T90/T180/T270)
Section titled “Rotated text (T90/T180/T270)”Print text at a rotation angle.
T90 font size X Y "content"T180 font size X Y "content"T270 font size X Y "content"| Command | Rotation angle |
|---|---|
| T | 0° (default) |
| T90 | 90° |
| T180 | 180° |
| T270 | 270° |
Text scaling (SETMAG)
Section titled “Text scaling (SETMAG)”Set the text scaling multipliers.
SETMAG horizontal_multiplier vertical_multiplier| Parameter | Description | Range |
|---|---|---|
| Horizontal multiplier | Horizontal multiplier | 1-8 |
| Vertical multiplier | Vertical multiplier | 1-8 |
Example:
SETMAG 2 2TEXT 24 0 50 50 "放大两倍的文字"SETMAG 1 1Bold (SETBOLD)
Section titled “Bold (SETBOLD)”Set text boldness.
SETBOLD switch| Parameter | Description |
|---|---|
| 1 | Enable bold |
| 0 | Disable bold |
Example:
SETBOLD 1TEXT 24 0 50 50 "加粗文字"SETBOLD 0Underline (UNDERLINE)
Section titled “Underline (UNDERLINE)”Set text underlining.
UNDERLINE switch| Parameter | Description |
|---|---|
| ON | Enable underline |
| OFF | Disable underline |
Example:
UNDERLINE ONTEXT 24 0 50 50 "带下划线的文字"UNDERLINE OFFAlignment
Section titled “Alignment”Set text alignment.
CENTERLEFTRIGHTExample:
CENTERTEXT 24 0 0 50 "居中文本"LEFTTEXT 24 0 30 100 "左对齐文本"RIGHTTEXT 24 0 0 150 "右对齐文本"Reverse text (INVERSE-LINE)
Section titled “Reverse text (INVERSE-LINE)”Print reverse text.
INVERSE-LINE X Y width height| Parameter | Description |
|---|---|
| X | Reverse area starting X coordinate |
| Y | Reverse area starting Y coordinate |
| Width | Reverse area width |
| Height | Reverse area height |
Barcode printing commands
Section titled “Barcode printing commands”1D barcode (BARCODE)
Section titled “1D barcode (BARCODE)”Print a one-dimensional barcode.
BARCODE type narrow_bar_width wide_to_narrow_ratio height X Y "content"| Parameter | Description |
|---|---|
| Type | Barcode type |
| Narrow bar width | Narrow bar width |
| Wide-to-narrow ratio | Wide-to-narrow bar ratio |
| Height | Barcode height (dot) |
| X | Barcode starting X coordinate |
| Y | Barcode starting Y coordinate |
| Content | Barcode data |
Supported barcode types
Section titled “Supported barcode types”| Type | Description | Default narrow bar width |
|---|---|---|
| 128 | Code 128 | 2 |
| 39 | Code 39 | 2 |
| 93 | Code 93 | 1 |
| CODABAR | Codabar | 2 |
| EAN8 | EAN-8 | 2 |
| EAN13 | EAN-13 | 2 |
| UPCA | UPC-A | 2 |
| UPCE | UPC-E | 2 |
| I2OF5 | Interleaved 2 of 5 | 2 |
Example:
BARCODE 128 1 2 50 50 200 "1234567890"BARCODE EAN13 1 2 60 50 300 "6901234567890"Rotated barcodes
Section titled “Rotated barcodes”Print a rotated barcode.
VBARCODE type narrow_bar_width wide_to_narrow_ratio height X Y "content"BARCODE90 type narrow_bar_width wide_to_narrow_ratio height X Y "content"BARCODE180 type narrow_bar_width wide_to_narrow_ratio height X Y "content"BARCODE270 type narrow_bar_width wide_to_narrow_ratio height X Y "content"| Command | Rotation angle |
|---|---|
| BARCODE | 0° (default) |
| VBARCODE | 90° |
| BARCODE90 | 90° |
| BARCODE180 | 180° |
| BARCODE270 | 270° |
QR code printing commands
Section titled “QR code printing commands”QR code (BARCODE QR)
Section titled “QR code (BARCODE QR)”Print a QR code.
SETQRVER error_correction_level_valuerotation_angleQR X Y M 2 U widtherror_correction_levelA,contentENDQR| Parameter | Description |
|---|---|
| Error correction level value | L=1, M=2, Q=3, H=4 |
| Rotation angle | 0/90/180/270 |
| X | QR code starting X coordinate |
| Y | QR code starting Y coordinate |
| Width | Cell width (2-20) |
| Error correction level | L/M/Q/H |
| Content | QR code data |
Error correction level
Section titled “Error correction level”| Level | Numeric value | Error correction capacity |
|---|---|---|
| L | 1 | 7% |
| M | 2 | 15% |
| Q | 3 | 25% |
| H | 4 | 30% |
Example:
SETQRVER 20QR 50 100 M 2 U 6MA,https://example.comENDQRGraphics drawing commands
Section titled “Graphics drawing commands”Draw a line (LINE)
Section titled “Draw a line (LINE)”Draw a straight line, including diagonal lines.
LINE X1 Y1 X2 Y2 width| Parameter | Description |
|---|---|
| X1 | Start point X coordinate |
| Y1 | Start point Y coordinate |
| X2 | End point X coordinate |
| Y2 | End point Y coordinate |
| Width | Line width |
Example:
LINE 30 100 546 100 2LINE 30 100 200 300 1Rectangular outline (BOX)
Section titled “Rectangular outline (BOX)”Draw a rectangular outline.
BOX X1 Y1 X2 Y2 width| Parameter | Description |
|---|---|
| X1 | Top-left X coordinate |
| Y1 | Top-left Y coordinate |
| X2 | Bottom-right X coordinate |
| Y2 | Bottom-right Y coordinate |
| Width | Border line width |
Example:
BOX 30 50 546 350 2Image printing commands
Section titled “Image printing commands”Image (EG/CG)
Section titled “Image (EG/CG)”Print a bitmap image.
EG width_in_bytes height X Y image_dataCG width_in_bytes height X Y image_data| Parameter | Description |
|---|---|
| Width in bytes | Image width/8 |
| Height | Image height (dot) |
| X | Image starting X coordinate |
| Y | Image starting Y coordinate |
| Image data | Hexadecimal image data |
Watermark (WATERMARK)
Section titled “Watermark (WATERMARK)”Print a watermark image.
Query commands
Section titled “Query commands”Query printer status
Section titled “Query printer status”{S}Query serial number (SN)
Section titled “Query serial number (SN)”{SN}Query printer model
Section titled “Query printer model”{M}Query firmware version
Section titled “Query firmware version”{V}Query battery level
Section titled “Query battery level”{B}Print control commands
Section titled “Print control commands”Print (PRINT)
Section titled “Print (PRINT)”Execute the print job. Every CPCL job must end with a PRINT command.
PRINTComplete examples
Section titled “Complete examples”Product label
Section titled “Product label”! 0 200 200 400 1PAGE-WIDTH 576CENTERSETMAG 2 2TEXT 24 0 0 30 "商品标签"SETMAG 1 1LEFTLINE 30 80 546 80 2TEXT 24 0 30 100 "名称: 有机苹果"TEXT 24 0 30 140 "规格: 500g/袋"TEXT 24 0 30 180 "产地: 山东烟台"SETBOLD 1TEXT 24 0 30 220 "价格: ¥25.90"SETBOLD 0BARCODE 128 1 2 50 100 280 "6901234567890"SETQRVER 20QR 400 100 M 2 U 5MA,https://example.com/product/123ENDQRPRINTShipping label
Section titled “Shipping label”! 0 200 200 800 1PAGE-WIDTH 576BOX 20 20 556 780 2CENTERSETMAG 2 2TEXT 24 0 0 40 "快递单"SETMAG 1 1LINE 20 90 556 90 2LEFTTEXT 24 0 40 110 "寄件人: 张三"TEXT 24 0 40 150 "电话: 138****1234"TEXT 24 0 40 190 "地址: 上海市浦东新区"LINE 20 230 556 230 1TEXT 24 0 40 250 "收件人: 李四"TEXT 24 0 40 290 "电话: 139****5678"TEXT 24 0 40 330 "地址: 北京市朝阳区xxx路xxx号"LINE 20 380 556 380 2CENTERBARCODE 128 2 2 80 0 420 "SF1234567890123"TEXT 7 0 0 520 "SF1234567890123"SETQRVER 20QR 200 580 M 2 U 8MA,SF1234567890123ENDQRPRINTSDK integration
Section titled “SDK integration”To integrate CPCL commands in an application, see the SDK guide for your language:
- Dart SDK - Cross-platform Flutter applications
- Java SDK - Native Android applications
- JavaScript SDK - WeChat Mini Programs / UniApp
- OpenHarmony SDK - HarmonyOS / OpenHarmony applications
- Objective-C SDK - Native iOS applications
- Swift SDK - iOS/macOS applications