vue实现静默打印pdf
欣赏器中想要打印文件,不依靠欣赏器自带的打印窗口,想要实现静默打印(也就是不弹出打印对话框),同时控制打印份数的功能,一种方式是利用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://
https://i-blog.csdnimg.cn/direct/42200fb0e6bc4ca2aa59235dd685d0e4.png
实现步骤
安装 electron-hiprint
上面有安装地点,好比windows 64位的选择这个安装包下载,并利用管理员身份安装
https://i-blog.csdnimg.cn/direct/72003474bcb94317bd6c274c5b6e8989.png
安装完成并启动后
https://i-blog.csdnimg.cn/direct/d7f197bdc04948eea647b813f59ca6c3.png
在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的话在此处,应用即可。
https://i-blog.csdnimg.cn/direct/4b0091551a6248f6882fe65ce1900734.png
有打印成功的状态返回
https://i-blog.csdnimg.cn/direct/900f6fd6a50f4c7cb2a56439975d1d77.png
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]