Pang Label Designer
Pang Label Designer 是一个基于 Web 的标签设计工具,用于设计和生成热敏/热转印打印标签。
项目地址
使用方法
1. 安装依赖
npm install @package/pang-label-designer
2. 初始化设计器
export interface DesignerOptions {
showImportExport?: boolean; // 是否显示导入导出按钮
width: number; // 标签宽度(mm)
height: number; // 标签高度(mm)
dpi?: DPI; // 分辨率
}
import { LabelDesigner } from '@package/pang-label-designer';
const designer = new Designer('container', options);
3. 使用设计器
designer.addComponent(ComponentType.TEXT, {
id: 'text1',
position: { x: 10, y: 10 },
content: 'Hello, Pang Label Designer!',
fontSize: 10,
});
4. 导出布局
const layout = designer.exportToJson();
console.log(layout);
5. 导入布局
const layout = designer.importFromJson(json);
布局文件格式
{
"label": {
"width": 100,
"height": 50,
"dpi": 203,
"dotsWidth": 800,
"dotsHeight": 400,
"scale": 4,
"unit": "mm"
},
"components": [
{
"id": "component-1730799879152",
"customId": "",
"type": "TEXT",
"position": {
"mm": {
"x": 12,
"y": 8.25
},
"dots": {
"x": 96,
"y": 66
}
},
"content": "data.group",
"font": {
"mm": {
"size": 3
},
"dots": {
"size": 24
}
},
"style": {
"rotation": 0,
"fontFamily": "Arial",
"fontWeight": "normal",
"fontStyle": "normal",
"textAlign": "left",
"textDecoration": "none",
"color": "#000000"
}
},
{
"id": "component-1730799923750",
"customId": "",
"type": "IMAGE",
"position": {
"mm": {
"x": 7.75,
"y": 19.75
},
"dots": {
"x": 62,
"y": 158
}
},
"imagePath": "",
"size": {
"mm": {
"width": 12.5,
"height": 12.5
},
"dots": {
"width": 100,
"height": 100
}
},
"style": {
"rotation": 0
}
},
{
"id": "component-1730799928984",
"customId": "",
"type": "BARCODE",
"position": {
"mm": {
"x": 24.25,
"y": 25.5
},
"dots": {
"x": 194,
"y": 204
}
},
"content": "12345678",
"size": {
"mm": {
"width": 38,
"height": 15.5
},
"dots": {
"width": 304,
"height": 124
}
},
"barcodeConfig": {
"type": "CODE128",
"showText": true,
"textPosition": "bottom",
"textAlign": "center",
"font": {
"mm": {
"size": 3
},
"dots": {
"size": 24
}
},
"quietZone": {
"mm": 1,
"dots": 8
},
"rotation": 0
},
"validation": {
"isValid": true
}
},
{
"id": "component-1730799938851",
"customId": "",
"type": "QRCODE",
"position": {
"mm": {
"x": 54.25,
"y": 0
},
"dots": {
"x": 434,
"y": 0
}
},
"content": "https://example.com",
"size": {
"mm": {
"width": 25,
"height": 25
},
"dots": {
"width": 200,
"height": 200
}
},
"qrcodeConfig": {
"errorCorrectionLevel": "M",
"margin": 4,
"darkColor": "#000000",
"lightColor": "#FFFFFF"
}
}
]
}
功能特点
1. 标签设计
- 支持多种DPI设置 (203/300/600)
- 精确的毫米和打印点双单位系统
- 实时网格参考线
- 灵活的缩放控制 (50%-400%)
2. 组件支持
-
文本组件
- 可调整字体大小
- 支持文本旋转(0°/90°/180°/270°)
- 自定义字体样式
-
图片组件
- 支持多种图片格式
- 可调整大小和旋转
- 保持宽高比例
-
条码组件
- 支持多种条码类型
- CODE128
- EAN13/EAN8/EAN5/EAN2
- UPC/UPCE
- CODE39
- ITF14
- MSI
- Pharmacode
- 可配置显示文本
- 自定义边距和大小
- 支持多种条码类型
-
二维码组件
- 可调整大小
- 支持纠错级别设置
- 自定义边距
- 可定制颜色
-
直线组件
- 可调整长度和角度
- 支持不同线条样式
- 自定义线条粗细
3. 交互功能
- 拖拽添加组件
- 精确定位系统
- 组件大小调整
- 属性面板实时编辑
- 对齐参考线
4. 导出功能
- JSON格式布局导出
- 支持mm/dots双单位
- 包含完整组件属性
- 条码内容格式验证
技术规格
支持的DPI
打印机的最小打印成像单位为点(dot),不同打印机分辨DPI对应最小打印单位换算关系如下:
- 203 DPI 1dot= 0.125mm(8 dots/mm)
- 300 DPI 1dot= 0.085mm(11.8 dots/mm)
- 600 DPI 1dot= 0.042mm(23.6 dots/mm)
标签尺寸
- 宽度: 0-100mm
- 高度: 0-100mm
- 精度: 0.1mm
组件规格
-
文本组件
- 字体大小: 0.1-100mm
- 旋转角度: 0°/90°/180°/270°
-
条码组件
- 最小条宽: 0.2mm
- 最小高度: 2mm
- 人眼可识别字符高度: 0.5-5mm
-
二维码组件
- 最小单元大小: 0.2mm
- 纠错级别: L(7%)/M(15%)/Q(25%)/H(30%)
-
直线组件
- 最小线宽: 0.1mm
- 角度: 0-359°