安装相关依赖
安装 vue-plugin-hiprint
npm install vue-plugin-hiprint
JQuery
因为 vue-plugin-hiprint 使用到了 JQuery 所以需要安装对应依赖
npm i jquery --save-d
安装 打印客户端
根据自己的系统 安装,静默打印才需要用到
引入依赖
在 main.js 中引入 依赖
/**
* 打印插件 Hi Print <a href="https://github.com/CcSimple/vue-plugin-hiprint">参考地址</a>
*/
import { hiPrintPlugin } from 'vue-plugin-hiprint'
// hiPrintPlugin.disAutoConnect() // 取消自动连接直接打印客户端,如果设置了取消自动连接,后续是获取不到打印机列表的
Vue.use(hiPrintPlugin, '$pluginName')
/**
* 将Jquery挂载到 Vue实例中
*/
import jquery from 'jquery'
Vue.prototype.$ = jquery
打印 html 内容 - 简单使用
我这边的 demo是 打印条形码,其他的也差不多,纸张大小是 宽 18.9 毫米 高 9毫米
打印机纸张大小:
设计面板大小:
如果 打印出来 比较大,可以将 设计面板 宽 高 都设置比 打印机纸张小一点
实际效果:
完整代码 插件自带的二维码、条形码生成样式非常的难调,尤其是打印纸张小于5厘米的时候,官方条形码怎么调都不对,我调了很久还是放弃了,改为了 使用后端生成条形码、二维码 返回base64格式给前端,这样前端只需要调整图片大小就可以了
下面这个示例打印的条形码就是后端生成的图片
<!-- 标签设计页面 -->
<template>
<div>
<button @click="getPrinterList">获取打印机列表</button>
<button @click="confirmPrintPrint">打印</button>
<div id="printDiv" v-print="'#printDiv'" style="display: none;">
<!-- 这里打印内容 style 内容大小一定要小于 实际纸张大小,如果打印的纸张够大 可以忽略 -->
<div style="zoom: 1.1;display: inline-block;width: 18mm;height: 7mm;margin-left: 5px;">
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMj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f8At3/9KI6KKAD4Jf8AJIdC/wC3j/0okrxf4o+MV8T/ABJk0fVry5tfDmmXTQPHbruYlMh3x0LEggE9B+OSigD1f4ffETwHLdWHhLwvaXdsZN/lq8AUMVQszM2SSSFPJrR8Z/E3w/4T8TQ6H4gspXhltUuo51jEqgl3UgqeRjb1GetFFAHjPjTVdI8eeO9Ei+H2lyQagj/vLqKARb23KVfA6BMEljjr7V9TUUUAfP8A8LP+ThfGv/b9/wClaV1fx18aX3hbwxaWOmStBd6o7p56HDJGgG7aexO5Rn0z3oooA87+GXjD4deCbGO9vI7+516Vf31wbYMIs9Uj+bj3PU/Tivctd8a2mjeAB4vS3luLJoredY+FcxysgB9MgPnHtjPeiigDyfxx8T/hxr3g69tbbSWn1CeFltw1msbQSEcPv7YPPBOeneu1+Bem6ppnw2hTVElj865kmto5RgpCQuOD0BYM3/As96KKAOJ/aa/5lb/t7/8AaNe6atqMekaNfanMpaKzt5LhwOpCKWP8qKKAPkvSvFGi+I/G1x4g+Ic95cxLhobSBNyHnhOowi+g65575+k/A/jzQPGkN1DoMc8cWnrGrJJCI1UNu2hQD0+Q/pRRQByl98ZPBS6tqmmeINPkjubG5mtSXthOsqo7KCD15xnBHGeprifhgF13433mu+GNOl0/w6iyebGF2oFMe0KQOAS+H2jpj2oooA+jqKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/Z" style="width: 100%; height: 100%;">
</div>
</div>
</div>
</template>
<script>
// 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
// 例如:import 《组件名称》 from '《组件路径》';
import request from '@/utils/request'
import { defaultElementTypeProvider } from 'vue-plugin-hiprint'
export default {
// 组件名称
name: 'LabelDesignIndex',
// import引入的组件需要注入到对象中才能使用
components: {},
// 父组件传递值
props: {
},
data() {
// 这里存放数据
return {
hiprintTemplate: {}
}
},
// 监听属性 类似于data概念
computed: {},
// 监控data中的数据变化
watch: {},
// 生命周期 - 创建完成(可以访问当前this实例)
created() {
},
// 生命周期 - 挂载完成(可以访问DOM元素)
mounted() {
this.init()
},
beforeCreate() {}, // 生命周期 - 创建之前
beforeMount() {}, // 生命周期 - 挂载之前
beforeUpdate() {}, // 生命周期 - 更新之前
updated() {}, // 生命周期 - 更新之后
beforeDestroy() {}, // 生命周期 - 销毁之前
destroyed() {}, // 生命周期 - 销毁完成
activated() {},
// 方法集合
methods: {
// 初始化
init() {
// 初始化 打印对象
const hiprintTemplate_ = new this.$pluginName.PrintTemplate()
this.hiprintTemplate = hiprintTemplate_
},
// 获取打印机列表
getPrinterList() {
if (window.hiwebSocket.opened === false) {
this.$notify.error('打印机客户端未连接')
}
// 模板对象获取
const printerList_ = this.hiprintTemplate.getPrinterList()
console.info(printerList_)
},
// 使用 hiPrintPlugin 控件打印
confirmPrintPrint() {
// 如果在 main.js 中设置了取消自动连接客户端 是获取不到打印机列表的!!!
if (window.hiwebSocket.opened === false) {
this.$notify.error('打印机客户端未连接,请点击右上角头像下载打印客户端')
}
// 这一句代码 如果打印出来有问题 可以尝试加进去,没有出现 则不用加
// 初始化 provider
this.$pluginName.init({
providers: [defaultElementTypeProvider()]
})
// 这一句代码 如果打印出来有问题 可以尝试加进去,没有出现 则不用加
this.$pluginName.PrintElementTypeManager.buildByHtml(this.$('.ep-draggable-item'))
// 不要使用 this.hiprintTemplate 打印,会出现重复打印,如果要用,请每次打印 都清空内容
const hiprintTemplate_ = new this.$pluginName.PrintTemplate()
const panel = hiprintTemplate_.addPrintPanel({
'height': 9,
'width': 20,
'paperHeader': 0,
'paperFooter': 30,
'paperNumberLeft': 26,
'paperNumberTop': 6,
'paperNumberDisabled': true,
'orient': 1,
'scale': 1
})
// 这一块代码是可以 放在 create 页面创建完成后
// 打印html内容
panel.addPrintHtml({ options: { width: 20, height: 9, top: 0, left: 0, content: this.$('#printDiv').html() }})
// 预览打印
hiprintTemplate_ .print()
// 打印机列表
const printerList = hiprintTemplate_ .getPrinterList()
console.info('打印机列表', printerList)
// 直接打印 - 不带参数
hiprintTemplate_ .print2()
// 直接打印 带参数
hiprintTemplate_ ntTemplate.print2(null, {
printer: '', // 指定打印机 打印机 名称
title: '打印任务名称',
color: false, // 是否打印颜色 默认 true
copies: 1, // 打印份数 默认 1
});
}
}
}
</script>
<style lang='scss' scoped>
/**scoped 表示样式只在当前组件有效*/
</style>
具体更多打印api文档: 打印api
根据模版打印 - 简单使用
<!-- 标签设计页面 -->
<template>
<div>
<button @click="getPrinterList">获取打印机列表</button>
<button @click="confirmPrintPrint">打印</button>
<!-- 这里打印内容 style 内容大小一定要小于 实际纸张大小,如果打印的纸张够大 可以忽略 -->
<!-- 打印内容 -->
<div id="printDivXm3" />
</div>
</template>
<script>
// 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
// 例如:import 《组件名称》 from '《组件路径》';
import request from '@/utils/request'
import { defaultElementTypeProvider } from 'vue-plugin-hiprint'
export default {
// 组件名称
name: 'LabelDesignIndex',
// import引入的组件需要注入到对象中才能使用
components: {},
// 父组件传递值
props: {
},
data() {
// 这里存放数据
return {
hiprintTemplate: {}
}
},
// 监听属性 类似于data概念
computed: {},
// 监控data中的数据变化
watch: {},
// 生命周期 - 创建完成(可以访问当前this实例)
created() {
},
// 生命周期 - 挂载完成(可以访问DOM元素)
mounted() {
this.init()
},
beforeCreate() {}, // 生命周期 - 创建之前
beforeMount() {}, // 生命周期 - 挂载之前
beforeUpdate() {}, // 生命周期 - 更新之前
updated() {}, // 生命周期 - 更新之后
beforeDestroy() {}, // 生命周期 - 销毁之前
destroyed() {}, // 生命周期 - 销毁完成
activated() {},
// 方法集合
methods: {
// 初始化
init() {
// 初始化 打印对象
const hiprintTemplate_ = new this.$pluginName.PrintTemplate()
this.hiprintTemplate = hiprintTemplate_
},
// 获取打印机列表
getPrinterList() {
if (window.hiwebSocket.opened === false) {
this.$notify.error('打印机客户端未连接')
}
// 模板对象获取
const printerList_ = this.hiprintTemplate.getPrinterList()
console.info(printerList_)
},
// 使用 hiPrintPlugin 控件打印
confirmPrintPrint() {
// 如果在 main.js 中设置了取消自动连接客户端 是获取不到打印机列表的!!!
if (window.hiwebSocket.opened === false) {
this.$notify.error('打印机客户端未连接,请点击右上角头像下载打印客户端')
}
// 这一句代码 如果打印出来有问题 可以尝试加进去,没有出现 则不用加
// 初始化 provider
this.$pluginName.init({
providers: [defaultElementTypeProvider()]
})
// 这一句代码 如果打印出来有问题 可以尝试加进去,没有出现 则不用加
this.$pluginName.PrintElementTypeManager.buildByHtml(this.$('.ep-draggable-item'))
// 清空原内容
this.$('#printDivXm3').empty()
// 不使用全局对象, 使用模版打印,在线设计模版:https://ccsimple.gitee.io/vue-plugin-hiprint/
const hiprintTemplate_ = new this.$pluginName.PrintTemplate({
template: {
'panels': [
{
'index': 0,
'name': 1,
'height': 38,
'width': 45,
'paperHeader': 3,
'paperFooter': 101.175,
'printElements': [
{
'options': {
'left': 4.5,
'top': 15,
'height': 21,
'width': 118.5,
'field': 'boxNumberBarCode',
'testData': '',
'fontSize': 12,
'lineHeight': 18,
'textType': 'barcode',
'title': '箱号',
'right': 121.49514770507812,
'bottom': 26.996349334716797,
'vCenter': 62.245147705078125,
'hCenter': 16.496349334716797,
'coordinateSync': false,
'widthHeightSync': false,
'hideTitle': true,
'textAlign': 'center',
'qrCodeLevel': 0
},
'printElementType': {
'title': '条形码',
'type': 'text'
}
},
{
'options': {
'left': 3,
'top': 43.5,
'height': 9.75,
'width': 120,
'title': '箱号',
'right': 122.99514770507812,
'bottom': 44.24878692626953,
'vCenter': 62.995147705078125,
'hCenter': 39.37378692626953,
'field': 'boxNumber',
'testData': '124322023031302',
'coordinateSync': false,
'widthHeightSync': false,
'textAlign': 'center',
'qrCodeLevel': 0
},
'printElementType': {
'title': '文本',
'type': 'text'
}
},
{
'options': {
'left': 3,
'top': 58.5,
'height': 9.75,
'width': 120,
'title': 'MODEL',
'field': 'model',
'testData': '4.4>XLR',
'coordinateSync': false,
'widthHeightSync': false,
'textAlign': 'center',
'qrCodeLevel': 0,
'right': 122.99514770507812,
'bottom': 62.2500114440918,
'vCenter': 62.995147705078125,
'hCenter': 57.3750114440918
},
'printElementType': {
'title': '文本',
'type': 'text'
}
},
{
'options': {
'left': 3,
'top': 75,
'height': 9.75,
'width': 52.5,
'title': 'QTY',
'right': 122.99514770507812,
'bottom': 81.74878692626953,
'vCenter': 62.995147705078125,
'hCenter': 76.87378692626953,
'field': 'qty',
'testData': '300',
'coordinateSync': false,
'widthHeightSync': false,
'qrCodeLevel': 0
},
'printElementType': {
'title': '文本',
'type': 'text'
}
},
{
'options': {
'left': 64.5,
'top': 75,
'height': 9.75,
'width': 60,
'title': 'TO',
'right': 111,
'bottom': 107.24878692626953,
'vCenter': 81,
'hCenter': 102.37378692626953,
'field': 'language',
'testData': '英文',
'coordinateSync': false,
'widthHeightSync': false,
'qrCodeLevel': 0
},
'printElementType': {
'title': '文本',
'type': 'text'
}
},
{
'options': {
'left': 3,
'top': 90,
'height': 9.75,
'width': 120,
'title': '日期',
'field': 'date',
'testData': '2023-03-15',
'coordinateSync': false,
'widthHeightSync': false,
'textAlign': 'center',
'qrCodeLevel': 0
},
'printElementType': {
'title': '文本',
'type': 'text'
}
}
],
'paperNumberLeft': 96,
'paperNumberTop': 82.5,
'paperNumberDisabled': true,
'orient': 1
}
]
}
})
// 挂载打印内容
hiprintTemplate_.design('#printDivXm3')
// 打印数据,要和 上面 panel 内的 field 参数一致
const printData = {
boxNumberBarCode: '我是条形码内容',
boxNumber: '我是测试内容1',
model: '我是测试内容2',
qty: '我是测试内容3',
language: '我是测试内容4',
date: '2023-03-15'
}
// 预览打印
hiprintTemplate_.print(printData)
// 直接打印 带参数
hiprintTemplate_ ntTemplate.print2(printData, {
printer: '', // 指定打印机 打印机 名称
title: '打印任务名称',
color: false, // 是否打印颜色 默认 true
copies: 1, // 打印份数 默认 1
});
}
}
}
</script>
<style lang='scss' scoped>
/**scoped 表示样式只在当前组件有效*/
</style>
以下内容 和上面demo 没关系 !!!!
修改文本样式
进入 模版设计 模版设计
设计好模版 点击 查看模板Json
将 font 元素 加入到 option中,例如
panel.addPrintText({ options: { 'left': 10, 'top': 5, 'height': 15, 'width': 127.5, 'field': 'canshu1', 'testData': '测试数据', 'hideTitle': true, 'fontFamily': 'Microsoft YaHei',
'fontSize': 4 }})
官方所有 打印示例
这些示例都没有拖拽功能
Hi Print 源码 地址文章来源:https://www.toymoban.com/news/detail-411742.html
官网文章来源地址https://www.toymoban.com/news/detail-411742.html
// 下列方法都是没有拖拽设计页面的, 相当于代码模式, 使用代码设计页面
// 想要实现拖拽设计页面,请往下看 '自定义设计'
var hiprintTemplate = new this.$pluginName.PrintTemplate();
var panel = hiprintTemplate.addPrintPanel({ width: 100, height: 130, paperFooter: 340, paperHeader: 10 });
//文本
panel.addPrintText({ options: { width: 140, height: 15, top: 20, left: 20, title: 'hiprint插件手动添加text', textAlign: 'center' } });
//条形码
panel.addPrintText({ options: { width: 140, height: 35, top: 40, left: 20, title: '123456', textType: 'barcode' } });
//二维码
panel.addPrintText({ options: { width: 35, height: 35, top: 40, left: 165, title: '123456', textType: 'qrcode' } });
//长文本
panel.addPrintLongText({ options: { width: 180, height: 35, top: 90, left: 20, title: '长文本:hiprint是一个很好的webjs打印,浏览器在的地方他都可以运行' } });
//表格
panel.addPrintTable({ options: { width: 252, height: 35, top: 130, left: 20, content: $('#testTable').html() } });
//Html
panel.addPrintHtml({ options: { width: 140, height: 35, top: 180, left: 20, content:'' } });
//竖线//不设置宽度
panel.addPrintVline({ options: { height: 35, top: 230, left: 20 } });
//横线 //不设置高度
panel.addPrintHline({ options: { width: 140, top: 245, left: 120 } });
//矩形
panel.addPrintRect({ options: { width: 35, height: 35, top: 230, left: 60 } });
//打印
hiprintTemplate.print({});
//直接打印,需要安装客户端
hiprintTemplate.print2({});
到了这里,关于vue-plugin-hiprint vue hiprint vue使用hiprint打印控件VUE HiPrint HiPrint简单使用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!