# WebPrint **Repository Path**: jink2005/WebPrint ## Basic Information - **Project Name**: WebPrint - **Description**: Print directly to printers using Javascript. - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: https://github.com/jink2005/WebPrint - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-06-20 - **Last Updated**: 2026-11-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # WebPrint ![WebPrint](https://github.com/micwallace/WebPrint/blob/master/src/webprint/img/webprinticon.png) Print directly to printers using Javascript. WebPrint is a fork of QZ-print: https://github.com/qzindustries/qz-print It uses postMessage API and/or ajax calls to communicate with the Java applet. This differs from QZ-print, that uses Java Web Start and the Java deployment framework for communication. The Java deployment framework is set to be removed in early 2015, I wanted to find another way to use QZ-print, which provides a seamless printing experience for web applications. See an example.html/webprint.js for usage or [click here](https://wallaceit.com.au/webprint/example.html) for a live version of the example. If WebPrint has helped with your project, please donate to support it's future development. [![Donate to WebPrint](https://www.paypalobjects.com/en_AU/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7JBL64AV5XDWG) # OS Compatability The main Webprint applet (hosted here) is compatible with Windows, OSX and Linux. Android support is provided via the Android app: https://github.com/micwallace/webprint-android NOTE: Serial and HTML printing is not currently supported on Android. The javacript library will prompt you to install or open the correct applet if it is not running. # HTTPS usage If you site uses HTTPS, requests to HTTP server are almost certainly blocked by default due to mixed-content restrictions. Thankfully, WebPrint uses an innovative solution to avoid this by using an intermediary browser tab/window and the postMessage API. This negates the need for end-users to change their browser settings. For an example on how to use this feature, see example.html in the project. Note that the example prints ESC/P formatted data which may not be compatible with all printers. # How this came about Mid last year I developed an android applet that essentially accepts http requests and forwards them to the specified socket or network printer. https://github.com/micwallace/HttpSocketAdaptor After a few months I found this solution stopped working due to stronger mixed-content restrictions in most browsers. Thanks to the postMessage API I was able to securely avoid these restrictions. After that WebPrint was just a matter of time. # Thanks A big thanks to the qz-print guys for allowing this project to happen and EJ Technologies for providing their excellent cross platform installer. [![Install4j](https://www.ej-technologies.com/images/product_banners/install4j_large.png)](http://www.ej-technologies.com/products/install4j/overview.html) [Install4j: Multi-platform installer builder](http://www.ej-technologies.com/products/install4j/overview.html) # 构建(Windows 发行包) 本仓库现在只做 Windows x64 发行包(清单第七节),**不装 Ant 也能构建**: 1. 准备 **JDK8 且带 JavaFX**(8u441 / 更早;`%JAVA_HOME%\jre\lib\ext\jfxrt.jar` 必须存在)与 **PowerShell 7**(`pwsh`)。 2. 在仓库根目录跑一条命令: ```powershell pwsh -File build.ps1 # 组包 + 235 条回归 + 两条验收(默认 all) pwsh -File build.ps1 -Target package # 只出完整发行包 pwsh -File build.ps1 -Target jar # 只出 dist\WebPrint.jar pwsh -File build.ps1 -Target test # 235 条回归 pwsh -File build.ps1 -Target verify # 自包含 + 随包预置 两条验收 pwsh -File build.ps1 -Toolbelt powershell # 强制走旧的 PowerShell 打包脚本 pwsh -File build.ps1 -PreseedOrigin https://your.domain -Target package ``` 3. 产物在 `dist\`:`WebPrint.jar`(6.1 MB)、`jre\`(自带 Java 8 + JavaFX,201.1 MB)、`WebPrint.bat`、 `WebPrint-console.bat`、`README.txt`、`webprint.js`、`webprint_acl.preseed.json`(随包预置授权), 以及 `WebPrint-1.8.7-wss-windows-full.zip`。 两条构建路径(`build-ant.xml` 跨平台编译/出 jar/组包;`tools\build-dist.ps1` 原有 7 步脚本)读同一套模板 `tools\dist-templates\`,产物同构。Ant 是可选依赖:装了 NetBeans 就直接用它的 `\extide\ant`(本机实测 1.10.15),没有则用 PowerShell 脚本;也可 `-AntPath` 指定、或 `-Toolbelt powershell` 强制走脚本。 环境自检:`ant -f build-ant.xml doctor`。 细节(Ant 便携版安装、合并 jar 必须剔除签名文件、JRE 裁剪清单、验收脚本):见 `docs\构建与打包说明.md`。 # 发布升级包 升级源是业务站自己的静态目录(不引入对象存储):`https://www.lnnear.com/download/webprint/` (元数据 `update.json` + 带版本号的 jar / zip,支持 Range 与 HTTPS)。 ```powershell pwsh -File tools\publish-update.ps1 # 只发增量 jar(约 6.2 MB) pwsh -File tools\publish-update.ps1 -WithZip # 同时发整包(约 88.7 MB,新机器首次部署用) pwsh -File tools\publish-update.ps1 -Notes "修复xxx" -Mandatory pwsh -File tools\publish-update.ps1 -NoUpload # 只生成 build\update.json,不上传 ``` 脚本会算 SHA-256、生成 `update.json`、`scp` 到 `/var/www/download/webprint/`、把 `WebPrint.zip` 软链到新整包, 最后**回读线上文件再算一次 hash** 才报成功。客户端侧:服务启动 45 秒后自动检查一次、此后每 6 小时一次, 结果显示在管理页「版本与升级」卡;`webprint.config` 里可用 `update.url / update.channel / update.auto` 调整。 升级是「自动查、人工点」:托盘只有一个升级菜单项,状态机 `检查更新… → 下载新版本 x.y.z… → 升级到 x.y.z(已下载)…`, 每一步点一下推进,没到该走的步骤不会提前显示;管理页「版本与升级」卡也提供同样的下载/升级按钮。替换由独立的 `apply-update.bat` 在进程退出后执行(备份旧 jar → 覆盖 → 重启 → 轮询 `/admin` 健康检查,失败自动回滚),过程写程序目录 `update-apply.log`。 细节与验收记录见 `docs\升级通道说明.md`。 # 运行 解压发行包,双击 `WebPrint.bat`。启动脚本只用随包 `jre\`,目标机不需要安装 Java; 找不到 `jre\bin\javaw.exe` 会打印原因并停下(不会回退到系统 Java)。 - HTTP `8888`、ws `8899`、wss `8181`(`%APPDATA%\WebPrint\webprint.config` 可改) - 管理页:http://127.0.0.1:8888/admin ;自包含说明见 `docs\自包含运行时说明.md` - 托盘右键菜单:关于 / 设置 / 打印机 / **管理页(Admin)** / **检查更新…(按状态变成下载/升级)** / 安装本地证书 / 退出。 菜单项按状态推进:先查、查到新版本再下载、下载完才出现「升级到 x.y.z(已下载)」,确认后才重启替换; 启动日志会打一行「托盘菜单:…」便于排查。 # 历史(QZ Tray 上游遗留,不再使用) 下面这套来自上游 QZ Tray,本分支已废弃: - **编译**:`ant`(NetBeans 生成的 `build.xml`,`javac.classpath=${ivy.classpath}` 要 Ivy 在线解析, 并绑死 `platform.active=JDK_1.8_152`)。`build.xml` 仍留在仓库,仅作历史;当前用 `build-ant.xml` / `build.ps1`。 - **打包安装器**:`ant nsis` / `ant pkgbuild` / `ant makeself`,以及 `webprint.install4j`(EJ Technologies 商业工具)。 当前只发 zip 免安装包,不做安装器。 - **依赖安装**:brew / apt / yum 装 `ant`、`nsis`、`makeself`、`openjdk-7-jdk` 的说明 —— macOS / Linux 打包不在范围内。 - 日志位置(QZ 时代):Windows `%APPDATA%\qz`、mac `~/Library/Application Support/qz`、Linux `~/.qz`; WebPrint 现在写 `%APPDATA%\WebPrint\logs\`。