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.
25 - Book label
Bookstore label (60×40mm): title, author, list price, and book 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:10px;top:8px;width:150px;height:44px;box-sizing:border-box;overflow:hidden;font-size:18px;font-weight:700;color:#0F172A;white-space:pre-wrap">设计中的设计</div>
<div style="position:absolute;left:10px;top:52px;width:112px;height:9px;box-sizing:border-box;overflow:hidden;font-size:5.5px;color:#94A3B8;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">DESIGN OF DESIGN</div>
<div style="position:absolute;left:132px;top:54px;width:85px;height:54px;box-sizing:border-box;overflow:hidden;display:flex;flex-direction:column;align-items:center;justify-content:center"><svg width="85" height="40" viewBox="0 0 85 40" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none"><rect x="0" y="0" width="1" height="40" fill="#111"/><rect x="3" y="0" width="3" height="40" fill="#111"/><rect x="8" y="0" width="3" height="40" fill="#111"/><rect x="12" y="0" width="1" height="40" fill="#111"/><rect x="14" y="0" width="1" height="40" fill="#111"/><rect x="17" y="0" width="2" height="40" fill="#111"/><rect x="22" y="0" width="1" height="40" fill="#111"/><rect x="24" y="0" width="2" height="40" fill="#111"/><rect x="29" y="0" width="2" height="40" fill="#111"/><rect x="34" y="0" width="1" height="40" fill="#111"/><rect x="36" y="0" width="1" height="40" fill="#111"/><rect x="38" y="0" width="2" height="40" fill="#111"/><rect x="42" y="0" width="3" height="40" fill="#111"/><rect x="46" y="0" width="1" height="40" fill="#111"/><rect x="49" y="0" width="3" height="40" fill="#111"/><rect x="54" y="0" width="3" height="40" fill="#111"/><rect x="58" y="0" width="1" height="40" fill="#111"/><rect x="60" y="0" width="1" height="40" fill="#111"/><rect x="63" y="0" width="2" height="40" fill="#111"/><rect x="68" y="0" width="1" height="40" fill="#111"/><rect x="70" y="0" width="2" height="40" fill="#111"/><rect x="75" y="0" width="2" height="40" fill="#111"/><rect x="80" y="0" width="1" height="40" fill="#111"/><rect x="82" y="0" width="1" height="40" fill="#111"/></svg><div style="text-align:center;font-size:5.5px;line-height:1.2;margin-top:1px">9787563394180</div></div>
<div style="position:absolute;left:10px;top:66px;width:112px;height:14px;box-sizing:border-box;overflow:hidden;font-size:8.5px;color:#0F172A;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">原研哉 著</div>
<div style="position:absolute;left:10px;top:82px;width:112px;height:14px;box-sizing:border-box;overflow:hidden;font-size:8px;color:#64748B;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">山东人民出版社</div>
<div style="position:absolute;left:10px;top:98px;width:54px;height:16px;box-sizing:border-box;overflow:hidden;background:#4C1D95;border:1px solid #4C1D95;box-sizing:border-box"></div>
<div style="position:absolute;left:10px;top:98px;width:54px;height:16px;box-sizing:border-box;overflow:hidden;font-size:6.5px;color:#FFFFFF;text-align:center;display:flex;align-items:center;justify-content:center;white-space:pre-wrap">设计艺术</div>
<div style="position:absolute;left:10px;top:114px;width:80px;height:18px;box-sizing:border-box;overflow:hidden;font-size:14px;font-weight:700;color:#4C1D95;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">¥ 68.00</div>
<div style="position:absolute;left:132px;top:114px;width:85px;height:12px;box-sizing:border-box;overflow:hidden;font-size:6px;color:#0F172A;text-align:right;display:flex;align-items:center;justify-content:flex-end;white-space:pre-wrap">索书号 I267.1/Y94</div>
<div style="position:absolute;left:10px;top:133px;width:150px;height:12px;box-sizing:border-box;overflow:hidden;font-size:5px;color:#94A3B8;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">悦享书店 · 文二路店</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.