# electron-hiprint-form-cc_simple **Repository Path**: Jlanglang/electron-hiprint-form-cc_simple ## Basic Information - **Project Name**: electron-hiprint-form-cc_simple - **Description**: electron-hiprint-form-cc_simple - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-09-15 - **Last Updated**: 2026-11-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # xfirelong 打印插件 本机打印客户端:网页通过 socket.io 连 `http://localhost:17521`,把「打印 HTML / PDF」的任务交给本机打印机静默出纸,不弹浏览器打印框。 基于 [CcSimple/electron-hiprint](https://gitee.com/CcSimple/electron-hiprint)(MIT)定制,与上游的差异见文末。 ## 能做什么 - 静默打印 HTML(vue-plugin-hiprint 的模板,或直接给 HTML 字符串) - 打印 PDF:本地路径、网络 URL、前端生成的二进制(面单走这个) - 打印记录:成功/失败、时间(本机时区)、重打、打开 PDF、打开所在目录 - 托盘常驻、开机自启、端口 / token / 默认打印机可配 - 支持 `hiprint://` 协议从网页唤起客户端 ## 安装与运行 - 安装包:Windows x64 `hiprint-.exe`、macOS arm64 `hiprint_mac_arm64-.dmg` - 启动后托盘常驻,默认端口 **17521**、token 为空,本机自用不需要改 - 从源码跑(Node 16 / 18): ```bash npm install npm start ``` ## 网页接入 ```js import { io } from "socket.io-client"; const socket = io("http://localhost:17521", { transports: ["websocket"] }); ``` ### 打印 HTML ```js socket.emit("news", { html, templateId: "唯一 id,用于对回调", printer: "打印机名称,不传用默认打印机", // 自定义纸张单位是 1/1000 mm:60mm × 80mm 写成 { width: 60000, height: 80000 } pageSize: { width: 60000, height: 80000 }, }); ``` ### 打印 PDF ```js // 本地文件或网络地址 socket.emit("news", { type: "url_pdf", pdf_path: "https://example.com/a.pdf", templateId, printer, }); // 前端生成的 PDF:必须是 Uint8Array / Buffer(Blob 要先转) socket.emit("news", { type: "blob_pdf", pdf_blob: new Uint8Array(await blob.arrayBuffer()), templateId, printer, pageSize: { width: 100000, height: 150000 }, }); ``` ### 打印回调 ```js socket.on("success", (res) => console.log("打印成功", res.templateId)); socket.on("error", (res) => console.error("打印失败", res.templateId, res.msg)); ``` > 为了兼容 `vue-plugin-hiprint` 0.0.56 之前的版本,成功事件同时会发一份 `successs`(三个 s)。 ### 查询打印状态 ```js // templateIds 为空时返回最近 20 条 socket.emit("getPrintStatus", { templateIds: [] }); socket.on("printStatus", (rows) => console.log(rows)); socket.on("printStatusError", (err) => console.error(err.msg)); ``` ## 打印记录 托盘右键 →「打印记录」,可以看每一条 `news` 的结果,支持重打、打开 PDF、打开所在目录。 ![打印记录](./res/Print_log.png) 单条任务可以禁止重打:请求里带 `rePrintAble: false`。 ## 配置 托盘右键 →「设置」,可改:端口、token、开机启动、关闭到托盘、PDF 缓存目录、默认打印机、连接通知、允许重打。 - 配置文件:`userData/config.json` - Windows:`%APPDATA%\hiprint\config.json` - macOS:`~/Library/Application Support/hiprint/config.json` - PDF 缓存默认目录 - Windows:`D:\xfirelong_print_cache` - macOS:`~/Library/Application Support/hiprint/xfirelong_print_cache` - 中转服务:本定制版默认关闭(`connectTransit: false`),只在跨网段打印时才需要配 `transitUrl` / `transitToken` ## 打包 ```bash npm run build-w-64 # Windows x64 → out/*.exe npm run build-m-arm64 # macOS arm64 → out/*.dmg(必须在 macOS 上打) npm run build-l # Linux → out/*.tar.xz / *.deb ``` macOS 包也可以交给 GitHub Actions:`.github/workflows/mac-build.yml`(`build-mac` 分支触发或手动 `workflow_dispatch`),产物是 `hiprint_mac_arm64-.dmg`。 **macOS 包没有签名**,首次打开若提示「已损坏」: ```bash sudo xattr -r -d com.apple.quarantine /Applications/hiprint.app ``` 或到「系统设置 → 隐私与安全性」点「仍要打开」。 ## 与上游的差异 - 品牌与默认路径:窗口标题、PDF 缓存目录改为 xfirelong - 打印记录增强:打开 PDF / 打开所在目录 / 本地时间显示 - macOS 兼容:PDF 缓存目录按平台取默认值、原生模块 `.node` 解包(否则 sqlite3 加载失败)、图标改用 png - 增加 macOS arm64 打包流水线 上游文档:[CcSimple/electron-hiprint](https://gitee.com/CcSimple/electron-hiprint) Web 打印设计器:[vue-plugin-hiprint](https://github.com/CcSimple/vue-plugin-hiprint) ## 许可 [MIT](./LICENSE)