在线样例
左侧浏览样例目录,右侧查看版式预览与示例代码;点击运行即可通过 web-print-pdf 驱动本地客户端完成静默打印或 PDF 预览。使用前请先 安装并启动客户端。
客户端
若打印或预览效果与预期不符,请务必先从官网下载并安装最新版 Web打印专家客户端后再试(旧版本可能导致版式偏差)。
版式说明
版式预览与打印输出完全遵循 HTML/CSS 标准样式,没有隐藏的渲染技巧:样式写成什么样,页面就长成什么样。
26 - 电器能效标
电器能效标打印样例。
版式预览
示例代码
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: 189px;
height: 113px;
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:2px;width:36px;height:12px;box-sizing:border-box;overflow:hidden;font-size:5.5px;color:#15803D;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">能效等级</div>
<div style="position:absolute;left:56px;top:8px;width:125px;height:16px;box-sizing:border-box;overflow:hidden;font-size:10px;font-weight:700;color:#15803D;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">中国能效标识</div>
<div style="position:absolute;left:10px;top:16px;width:36px;height:16px;box-sizing:border-box;overflow:hidden;background:#15803D;border:1px solid #15803D;box-sizing:border-box"></div>
<div style="position:absolute;left:10px;top:16px;width:36px;height:16px;box-sizing:border-box;overflow:hidden;font-size:9px;color:#FFFFFF;text-align:center;display:flex;align-items:center;justify-content:center;white-space:pre-wrap">1</div>
<div style="position:absolute;left:56px;top:28px;width:40px;height:30px;box-sizing:border-box;overflow:hidden;font-size:24px;font-weight:700;color:#15803D;text-align:center;display:flex;align-items:center;justify-content:center;white-space:pre-wrap">1</div>
<div style="position:absolute;left:10px;top:35px;width:36px;height:16px;box-sizing:border-box;overflow:hidden;background:#65A30D;border:1px solid #65A30D;box-sizing:border-box"></div>
<div style="position:absolute;left:10px;top:35px;width:36px;height:16px;box-sizing:border-box;overflow:hidden;font-size:9px;color:#FFFFFF;text-align:center;display:flex;align-items:center;justify-content:center;white-space:pre-wrap">2</div>
<div style="position:absolute;left:100px;top:36px;width:40px;height:14px;box-sizing:border-box;overflow:hidden;font-size:8px;color:#15803D;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">级能效</div>
<div style="position:absolute;left:10px;top:54px;width:36px;height:16px;box-sizing:border-box;overflow:hidden;background:#EAB308;border:1px solid #EAB308;box-sizing:border-box"></div>
<div style="position:absolute;left:10px;top:54px;width:36px;height:16px;box-sizing:border-box;overflow:hidden;font-size:9px;color:#FFFFFF;text-align:center;display:flex;align-items:center;justify-content:center;white-space:pre-wrap">3</div>
<div style="position:absolute;left:56px;top:62px;width:125px;height:14px;box-sizing:border-box;overflow:hidden;font-size:7px;color:#0F172A;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">KFR-35GW</div>
<div style="position:absolute;left:10px;top:73px;width:36px;height:16px;box-sizing:border-box;overflow:hidden;background:#F97316;border:1px solid #F97316;box-sizing:border-box"></div>
<div style="position:absolute;left:10px;top:73px;width:36px;height:16px;box-sizing:border-box;overflow:hidden;font-size:9px;color:#FFFFFF;text-align:center;display:flex;align-items:center;justify-content:center;white-space:pre-wrap">4</div>
<div style="position:absolute;left:56px;top:78px;width:125px;height:14px;box-sizing:border-box;overflow:hidden;font-size:7px;color:#0F172A;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">额定功率 1080 W</div>
<div style="position:absolute;left:10px;top:92px;width:36px;height:16px;box-sizing:border-box;overflow:hidden;background:#DC2626;border:1px solid #DC2626;box-sizing:border-box"></div>
<div style="position:absolute;left:10px;top:92px;width:36px;height:16px;box-sizing:border-box;overflow:hidden;font-size:9px;color:#FFFFFF;text-align:center;display:flex;align-items:center;justify-content:center;white-space:pre-wrap">5</div>
<div style="position:absolute;left:56px;top:94px;width:125px;height:10px;box-sizing:border-box;overflow:hidden;font-size:5.5px;color:#64748B;display:flex;align-items:center;justify-content:flex-start;white-space:pre-wrap">2026-10 生产</div>
<div style="position:absolute;left:56px;top:108px;width:125px;height:1px;box-sizing:border-box;overflow:hidden;background:#BBF7D0"></div>
</div>
</body>
</html>`;
await webPrintPdf.printHtml(html, {
width: '50mm',
height: '30mm',
margin: { top: '0', bottom: '0', left: '0', right: '0' },
printBackground: true
}, {
// 实际打印时,须指定当前打印机上支持此尺寸的纸张名称(名称以 getPrinterPapers 返回为准),如果指定的纸张不符合此尺寸,效果是不对的。也可以不传递此参数,而是通过在当前软件打印机这个栏目的操作列,预先设置好 “打印首选纸张” 这个弹窗里的参数达到同样的效果
// …
运行结果
- 若无法打印或连接客户端失败,请参阅 本地Print succeeded,上线后无法打印?(HTTP 业务系统上线后常见)。
- 客户端内置「运行示例」页(
vueApp/.../examples/index.vue)提供更多可编辑 demo,与本页样例互补。 - 工具类样例(连接检测、打印机列表等)仅返回 JSON,不触发打印。