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.
If results look wrong, install the latest Web Print Expert client from our site first (older builds may cause layout drift).
Preview and print follow standard HTML/CSS only—no hidden tricks. What you style is what you get.
86 - Custom paper size
Use pdf width + height (omit paperFormat). Note: pdfOptions.margin: 0 only sets PDF page margins—it does not reset the HTML body default margin (~8px). For small custom sizes, set html, body { margin: 0; padding: 0; } in your HTML (see labelHtml below), or content height exceeds the page and you get an extra blank page. Set printOptions.paperFormat from getPrinterPapers for real printing.
Layout preview
Sample code
const labelWidth = '100mm';
const labelHeight = '80mm';
const labelHtml = (n) => `<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<style>
html, body { margin: 0; padding: 0; }
.label {
width: ${labelWidth};
height: ${labelHeight};
border: 1px solid #333;
padding: 8mm;
font-family: Arial, sans-serif;
box-sizing: border-box;
}
</style>
</head>
<body>
<div class="label">
<div style="font-size:10px;color:#999;margin-bottom:4px">DEMO ONLY · 非真实物流面单</div>
<div style="font-size:11px;color:#666">WP 演示物流 · 样例包裹贴</div>
<div style="font-size:16px;font-weight:bold;margin:6px 0">收件人(虚构):陈晓雯</div>
<div style="font-size:12px">浙江省杭州市滨江区网商路 520 号</div>
<div style="margin-top:8px;font-size:20px;font-weight:bold;letter-spacing:2px">包裹编号 WP-${n}</div>
</div>
</body>
</html>`;
await webPrintPdf.printHtml(labelHtml('DEMO-001'), {
width: labelWidth,
height: labelHeight,
margin: { top: '0', bottom: '0', left: '0', right: '0' }
}, {
// 实际打印时,须指定当前打印机上支持此尺寸的纸张名称(名称以 getPrinterPapers 返回为准),如果指定的纸张不符合此尺寸,效果是不对的。也可以不传递此参数,而是通过在当前软件打印机这个栏目的操作列,预先设置好 “打印首选纸张” 这个弹窗里的参数达到同样的效果
paperFormat: '100x80',
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.