hiprint结合vue2项目实现静默打印详细使用步骤

代码地址是:vue-plugin-hiprint: hiprint for Vue2/Vue3 ⚡打印、打印设计、可视化设计器、报表设计、元素编辑、可视化打印编辑

本地安装包地址:electron-hiprint 发行版 - Gitee.com

1、先安装hipint安装包在本地

2、项目运行npm(socket.io是为了实现自动打印下载的)

复制代码
npm install vue-plugin-hiprint
npm i jquery --save-d
npm install socket.io

3、在main.js文件中

复制代码
import {hiPrintPlugin} from 'vue-plugin-hiprint'
Vue.use(hiPrintPlugin, '$pluginName')

import $ from "jquery";
window.jquery = window.$ = $;
Vue.prototype.$ = jquery

4、在node_modules包中找到print-lock.css样式文件复制到项目中

找到后复制到public文件夹

在public文件夹的index.html文件引入这个css文件(说是防止样式重叠使用的)

复制代码
<!-- 引入vue-plugin-hiprint的样式 -->
<link rel="stylesheet" type="text/css" media="print" href="<%= BASE_URL %>print-lock.css"></link>
<link rel="stylesheet" type="text/css" media="print" href="https://cdn.jsdelivr.net/npm/vue-plugin-hiprint@latest/dist/print-lock.css">

5、在页面的具体使用

复制代码
print(){
  const styleStr = `<style>样式代码 </style>`;

  let hiprintTemplate = new this.$pluginName.PrintTemplate()
  Array.from(this.$refs.print).forEach(v=>{
    let panel = hiprintTemplate.addPrintPanel({ paperType:'A4',paperNumberDisabled:true})
    panel.addPrintHtml({options: {"left":15,"top":5, "content":`<html><head>${styleStr}</head><body>${v.innerHTML}</body> </html>` } })
  }) 

  this.$message({
    message: '正在执行打印操作,请稍等......',
    type: 'success',
    offset:350
  });
        
  hiprintTemplate.print2()//直接静默打印
  //hiprintTemplate.print()  预览打印
}

6、在App.vue加上隐藏的样式,这样不影响页面样式

复制代码
#hiwprint_iframe{
  display: none !important;
}

最后:一定要在启动了客户端的软件情况下点击打印按钮,不然会报错未连接客户端!

相关推荐
葡萄城技术团队1 小时前
SpreadJS V19.2 新特性揭秘:FILTERXML 函数
前端
行者全栈架构师1 小时前
Spring Boot 接入 MaxKey 单点登录:6 个内部系统,一次登录全通行
java·vue.js·后端
袋鼠云数栈UED团队2 小时前
AI Coding 方法论分析:同一个需求 SpecKit 、 Superpowers、 MattpocockSkills 不同设计
前端·aigc·ai编程
掰头战士2 小时前
Prompt Cache,如果agent全靠LLM方做隐式缓存实在不够用。
前端·llm·agent
万敏2 小时前
Vue3 全栈实战第九周:Node.js + Express 后端从零搭建实战记录
vue.js·node.js·全栈
LEE2 小时前
前端转型全栈 01:数据建模,前端最大的盲区
前端·javascript·后端
货拉拉技术2 小时前
个人提效,攒不成组织提效:货拉拉 AI Coding 落地实践
前端
雪芽蓝域zzs2 小时前
第四十七节:驾驶舱大屏 ECharts 图表集成
前端·javascript·vue.js
Software攻城狮2 小时前
【React 学习方向(项目上手注意点)】
前端
林太白3 小时前
js-var和let以及const区别
前端·面试