Remote print configuration

For ERP, WMS, or OMS-driven jobs, configure WebSocket or HTTP polling on the client to receive and print automatically.

How it works

In remote mode the client listens to <strong>your business server</strong>. Incoming jobs use the same local pipeline as <code>printHtml</code>—no browser involved.

  1. ERP/WMS 生成与 printHtml 相同结构的 JSON
  2. 通过 WebSocket 推送或 HTTP 接口返回给客户端
  3. 客户端校验必要字段后执行打印
  4. 本地排版转 PDF → 静默出纸

Standard message format

Match the client’s test-task JSON shape; organize server payloads with these fields:

{
  "id": "uuid",
  "timestamp": 1710000000000,
  "type": "printHtml",
  "content": "<div>快递面单 #10086</div>",
  "pdfOptions": {
    "paperFormat": "A4",
    "margin": { "top": "20px", "bottom": "20px", "left": "20px", "right": "20px" },
    "printBackground": false
  },
  "printOptions": { "paperFormat": "A4", "printerName": "默认打印机" },
  "extraOptions": { "requestTimeout": 15 }
}

type can be printHtmlByUrl, printPdfByUrl, batchPrint, etc.

Client setup

Configure in client UI Remote Print settings:

配置操作说明
保存远程打印配置Body: { method: "websocket"|"http", url: "..." }
读取当前配置Read current config
清空配置Clear config

After saving, the client keeps a WS connection or polling loop and prints on valid messages.

Use built-in test endpoints in the client to verify setup (local WS/HTTP test URLs; port shown in the UI).

WebSocket mode

The client connects to your WS URL and prints on JSON tasks; reconnects automatically after network issues.

Server push example (Node.js):

const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 9000 });

function buildTask() {
  return {
    id: crypto.randomUUID(),
    timestamp: Date.now(),
    type: 'printHtml',
    content: '<div>WMS 面单</div>',
    pdfOptions: { paperFormat: 'A4' },
    printOptions: { paperFormat: 'A4' },
    extraOptions: { requestTimeout: 15 }
  };
}

wss.on('connection', (ws) => {
  ws.send(JSON.stringify(buildTask()));
});

Set the client URL to your WS service. Do not push when idle.

HTTP polling mode

The client polls your URL on a fixed interval and parses a unified response shape:

// 无任务
{ "success": true, "data": null }

// 有任务(data 为完整打印消息)
{
  "success": true,
  "data": {
    "id": "...",
    "timestamp": 1710000000000,
    "type": "printHtml",
    "content": "<div>...</div>",
    "pdfOptions": { ... },
    "printOptions": { ... },
    "extraOptions": { ... }
  }
}

Printing runs only when the task object includes required fields (e.g. id, timestamp, type).

Pull server example (Express):

const express = require('express');
const app = express();
const queue = [];

app.get('/api/print/pull', (req, res) => {
  const task = queue.shift();
  res.json({ success: true, data: task || null });
});

// 业务系统入队
app.post('/api/print/push', express.json(), (req, res) => {
  queue.push(req.body);
  res.json({ success: true });
});

app.listen(8080);

Set the client URL to your polling API.

Relation to printHtml

  • Remote: server push → client local print module
  • Local: browser page → webPrintPdf.printHtml
  • Both remote and local printHtml can coexist.
Download client free Documentation