Live demos

Enable JavaScript to use the live demos.

Your browser is too old for this page. Please use the latest Chrome, Edge, Firefox, or Safari.

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.

97 - Batch demo labels

Batch demo labels. When pdf uses width/height, printOptions.paperFormat must match the printer stock from getPrinterPapers.

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.batchPrint([
  { type: 'printHtml', data: labelHtml('001'), pdfOptions: { width: labelWidth, height: labelHeight, margin: { top: '0', bottom: '0', left: '0', right: '0' } } },
  { type: 'printHtml', data: labelHtml('002'), pdfOptions: { width: labelWidth, height: labelHeight, margin: { top: '0', bottom: '0', left: '0', right: '0' } } },
  { type: 'printHtml', data: labelHtml('003'), pdfOptions: { width: labelWidth, height: labelHeight, margin: { top: '0', bottom: '0', left: '0', right: '0' } } }
], {}, {
  // 实际打印时,须指定当前打印机上支持此尺寸的纸张名称(名称以 getPrinterPapers 返回为准),如果指定的纸张不符合此尺寸,效果是不对的。也可以不传递此参数,而是通过在当前软件打印机这个栏目的操作列,预先设置好 “打印首选纸张” 这个弹窗里的参数达到同样的效果
  paperFormat: '100x80',
  copies: 1,
  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.
Download client free View npm package