UniApp H5 silent print with desktop client

When UniApp builds to H5 in a desktop browser, integrate web-print-pdf like any web app. Mini programs cannot drive PC printers directly—use H5 stations or remote push to PCs.

Scope & prerequisites

  • Target PC browser H5 (WMS desk, POS, intranet) with the Web Print Expert client
  • Add web-print-pdf via npm or static import—same API as Vue

Architecture

UniApp H5 calls printHtml → local WebSocket client → printer. Same as the Vue guide.

UniApp H5 example

Import and wrap in setup or Options API:

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

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

Bind a print button in template

<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>

Platform limits

WeChat/Alipay mini programs cannot reach the desktop client—use server push to a PC station. See remote print.

Tips

  • Use #ifdef H5 around imports to avoid mini program bundle errors.
  • Capture print DOM via ref or HTML strings like the Vue guide.
  • On intranet H5, allow local WebSocket through security software.
  • Unlike <code>uni.print</code>, web-print-pdf supports <strong>silent</strong> named-printer output.

How this page fits with related guides

FAQ

Silent print in mini programs?

Not to PC clients—use H5 desks or remote push.

Different from Vue?

Same printHtml API—mind UniApp conditional compile and DOM access.

Native App WebView?

Evaluate WebSocket to local client; H5 desks or remote print are more common in production.

App WebView reach the local client?

WebView must reach 127.0.0.1 WebSocket—H5 desks or remote push are more common in production.

Mini program + PC print architecture?

Mini programs push jobs to the server; warehouse/front PCs run H5 + client printHtml—see WMS and remote print guides.

Client deployment by platform

The same web-print-pdf front-end runs on Windows, macOS, and Linux/domestic OS—install the matching client on each desktop.

Download client — free trial View npm package Documentation