UniApp H5 与桌面客户端静默打印

适用场景与准备

架构说明

UniApp H5 调用示例

// #ifdef H5
import webPrintPdf from 'web-print-pdf';

export async function silentPrint(html) {
  return webPrintPdf.printHtml(
    html,
    { paperFormat: 'A4', printBackground: true },
    { printerName: '默认打印机' }
  );
}
// #endif

模板中绑定打印按钮

<template>
  <view>
    <view id="print-area" v-html="reportHtml"></view>
    <button @click="onPrint">静默打印</button>
  </view>
</template>

<script setup>
// #ifdef H5
import { silentPrint } from '@/utils/print';
const onPrint = () => silentPrint(document.getElementById('print-area').innerHTML);
// #endif
</script>

平台边界(重要)

实践建议

与本站专题分工

常见问题

各平台客户端部署

免费下载客户端 查看 npm 包 开发文档