Live demos
Browse the sample list on the left and preview layouts plus sample code on the right. Run a demo to print silently or preview PDF via web-print-pdf and the local client. Install and launch the client first.
Client
If results look wrong, install the latest Web Print Expert client from our site first (older builds may cause layout drift).
Layout
Preview and print follow standard HTML/CSS only—no hidden tricks. What you style is what you get.
24 - Medicine price tag
Pharmacy price tag (60×40mm): generic name, strength, manufacturer, retail price, and drug barcode.
Layout preview
Sample code
const html = `<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>药品价签</title>
<style>
html, body { margin: 0; padding: 0; }
.biz-sheet {
position: relative;
width: 227px;
height: 151px;
box-sizing: border-box;
background: #fff;
font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
color: #0F172A;
overflow: hidden;
}
</style>
</head>
<body>
<div class="biz-sheet">
<div style="position:absolute;left:0px;top:0px;width:227px;height:26px;box-sizing:border-box;overflow:hidden;background:#C81E1E;border:1px solid #C81E1E;box-sizing:border-box"></div>
<div style="position:absolute;left:8px;top:4px;width:110px;height:18px;box-sizing:border-box;overflow:hidden;font-size:11px;font-weight:700;color:#FFFFFF;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">OTC 非处方药</div>
<div style="position:absolute;left:130px;top:6px;width:89px;height:14px;box-sizing:border-box;overflow:hidden;font-size:6.5px;color:#FECACA;text-align:right;display:flex;align-items:center;justify-content:flex-end;white-space:pre-wrap">请按说明书使用</div>
<div style="position:absolute;left:8px;top:34px;width:44px;height:12px;box-sizing:border-box;overflow:hidden;font-size:7px;color:#94A3B8;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">通用名</div>
<div style="position:absolute;left:118px;top:34px;width:40px;height:12px;box-sizing:border-box;overflow:hidden;font-size:7px;color:#94A3B8;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">规格</div>
<div style="position:absolute;left:8px;top:46px;width:104px;height:32px;box-sizing:border-box;overflow:hidden;font-size:13px;font-weight:700;color:#0F172A;white-space:pre-wrap">布洛芬缓释胶囊</div>
<div style="position:absolute;left:118px;top:46px;width:101px;height:18px;box-sizing:border-box;overflow:hidden;font-size:10px;color:#0F172A;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">0.3g × 20 粒</div>
<div style="position:absolute;left:118px;top:68px;width:40px;height:12px;box-sizing:border-box;overflow:hidden;font-size:7px;color:#94A3B8;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">生产企业</div>
<div style="position:absolute;left:118px;top:80px;width:101px;height:14px;box-sizing:border-box;overflow:hidden;font-size:8px;color:#0F172A;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">中美史克制药</div>
<div style="position:absolute;left:8px;top:82px;width:104px;height:12px;box-sizing:border-box;overflow:hidden;font-size:6.5px;color:#C81E1E;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">解热镇痛类</div>
<div style="position:absolute;left:8px;top:104px;width:211px;height:1px;box-sizing:border-box;overflow:hidden;background:#FCA5A5"></div>
<div style="position:absolute;left:8px;top:108px;width:118px;height:12px;box-sizing:border-box;overflow:hidden;font-size:6.5px;color:#0F172A;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">用法用量:一次 1 粒,一日 2 次</div>
<div style="position:absolute;left:130px;top:108px;width:89px;height:12px;box-sizing:border-box;overflow:hidden;font-size:6.5px;color:#0F172A;text-align:right;display:flex;align-items:center;justify-content:flex-end;white-space:pre-wrap">国药准字 H10900089</div>
<div style="position:absolute;left:8px;top:122px;width:118px;height:10px;box-sizing:border-box;overflow:hidden;font-size:6px;color:#0F172A;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">贮藏:密封,阴凉干燥处</div>
<div style="position:absolute;left:130px;top:122px;width:89px;height:14px;box-sizing:border-box;overflow:hidden;font-size:10px;font-weight:700;color:#C81E1E;text-align:right;display:flex;align-items:center;justify-content:flex-end;white-space:pre-wrap">¥ 18.00</div>
</div>
</body>
</html>`;
await webPrintPdf.printHtml(html, {
width: '60mm',
height: '40mm',
margin: { top: '0', bottom: '0', left: '0', right: '0' },
printBackground: true
}, {
// 实际打印时,须指定当前打印机上支持此尺寸的纸张名称(名称以 getPrinterPapers 返回为准),如果指定的纸张不符合此尺寸,效果是不对的。也可以不传递此参数,而是通过在当前软件打印机这个栏目的操作列,预先设置好 “打印首选纸张” 这个弹窗里的参数达到同样的效果
paperFormat: '60x40',
sharp: true /* 如果是热敏打印机,开启 sharp 抗锯齿,否则 false 即可 */
});
Result
- If printing fails or the client cannot connect, see Local print works—production does not? (common on HTTP deployments).
- The client’s built-in Run examples page has more editable demos; this page complements it.
- Utility demos (connection, printer list) return JSON only—no print job.