欣赏器中想要打印文件,不依靠欣赏器自带的打印窗口,想要实现静默打印(也就是不弹出打印对话框),同时控制打印份数的功能,一种方式是利用vue-plugin-hiprint和本地安装客户端electron-hiprint
原来是欣赏器去调用打印控件,现在直接在对应电脑上安装步伐,然后欣赏器去调用该步伐。
- 浏览器 -> electron-hiprint -> 打印
复制代码
- vue-plugin-hiprint:https://gitee.com/CcSimple/vue-plugin-hiprint
- electron-hiprint: https://gitee.com/CcSimple/electron-hiprint
- 下载地点:https://gitee.com/CcSimple/electron-hiprint/releases
- 找到指定体系版本,举行下载并安装
- 【安装注意:安装客户端时请 以管理员身份运行 ,才能成功添加 URLScheme】
- URLScheme hiprint://
实现步骤
安装 electron-hiprint
上面有安装地点,好比windows 64位的选择这个安装包下载,并利用管理员身份安装
安装完成并启动后
在vue项目中利用vue-plugin-hiprint
安装包
- npm install vue-plugin-hiprint
- # 或者
- yarn add vue-plugin-hiprint
复制代码 项目中引入包
- // 全局引入
- // main.js
- import { hiPrintPlugin } from 'vue-plugin-hiprint'
- Vue.use(hiPrintPlugin, '$pluginName')
- // 局部引入(推荐)
- import { hiPrintPlugin } from 'vue-plugin-hiprint'
复制代码 页面中利用
- <button @click="print">打印</YsButton>
- import { hiPrintPlugin } from 'vue-plugin-hiprint'
- async print() {
- const printer = hiprint.hiwebSocket.getPrinterList().find(i => i.isDefault); // 获取当前默认的打印机
- console.log(printer)
- // hiprint.hiwebSocket.send({ client: 'TEST_PRINT', printer: printer?.name, type: 'url_pdf', pdf_path: 'http://xx.xxx.xx.xx:1123/preview/xxx.pdf' }) // 指定打印机,同时配置客户端的token
- hiprint.hiwebSocket.send({ client: '', type: 'url_pdf', pdf_path: 'http://xx.xxx.xx.xx:1123/preview/xxx.pdf', pages: 1, copies: 2 }) // 设置打印的页数和打印的份数
- },
复制代码 如果必要设置客户端的token的话在此处,应用即可。
有打印成功的状态返回
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |