vue + html + Lodop打印功能

1.官网下载 http://www.lodop.net/download.html

2.解压安装运行

点击CLodop_Setup_for_Win32NT.exe进行安装

3.vue代码实现(具体操作见官网:http://www.lodop.net/faq/pp35.html)

3.1把官方提供的LodopFuncs.js文件保存到项目某个目录下

3.2 修改LodopFuncs.js文件, 在文件最底部添加一行代码

export { getLodop }; //导出getLodop

把该文件中的getLodop函数 export 出来

4.vue 前端代码

5.编写html页面

5.1 打印按钮

<el-button @click="btnClickPrint" size="small" type="primary">打印

5.2 html列表页面

dataList为Java后端接口查询的列表数据

序号 扫描人 问题数量 扫描页数 错误率
{{index + 1}} {{dataList[index] == null ? "" : dataList[index].scannedName}} {{dataList[index] == null ? "" : dataList[index].problemNumber}} {{dataList[index] == null ? "" : dataList[index].scanPageNumber}} {{dataList[index] == null ? "" : dataList[index].errorRate}}

5.3 定义data数据

data () {

return {

htmlCode: '',

tableShow: false,

}

}

5.4 打印方法

btnClickPrint () {

//1. 获取vue中html页面(vue页面编写style不要有scoped,会使html元素中携带data-v-123a743a,造成页面不显示。获取页面全部数据:this. e l . o u t e r H T M L ) t h i s . h t m l C o d e = t h i s . el.outerHTML) this.htmlCode = this. el.outerHTML)this.htmlCode=this.refs.problemContent.innerHTML

console.log(this.htmlCode)

// 因为html设置了v-show,获取html页面会携带style="display: none;"

this.htmlCode = this.htmlCode.replace('style="display: none;"','').replace(' ','')

//2. 参数(this.htmlCode) = 页面样式 + html页面代码

var strBodyStyle = ""

this.htmlCode = strBodyStyle + this.htmlCode

//3. 调用getLodop获取LODOP对象

let LODOP = getLodop()

//4. 初始化

LODOP.PRINT_INIT("")

//5. 参数设置(距上部高度 左边距 宽度 高度 html页面)

LODOP.ADD_PRINT_HTM("5%","5%","100%","90%",this.htmlCode)

//6. 打印 (输出pdf文件,底部含有LODOP打印标识:LODOP.PRINT())

LODOP.PREVIEW()

}

相关推荐
tg-zm8899961 天前
2025返利商城源码/挂机自动收益可二开多语言/自定义返利比例/三级分销理财商城
java·mysql·php·laravel·1024程序员节
X***C8621 天前
SpringBoot:几种常用的接口日期格式化方法
java·spring boot·后端
前端达人1 天前
你的App消息推送为什么石沉大海?看Service Worker源码我终于懂了
java·开发语言
oden1 天前
2025博客框架选择指南:Hugo、Astro、Hexo该选哪个?
前端·html
小光学长1 天前
基于ssm的宠物交易系统的设计与实现850mb48h(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
java·前端·数据库
编程大师哥1 天前
vxe-table 透视表分组汇总及排序基础配置
java
8***84821 天前
spring security 超详细使用教程(接入springboot、前后端分离)
java·spring boot·spring
9***J6281 天前
Spring Boot项目集成Redisson 原始依赖与 Spring Boot Starter 的流程
java·spring boot·后端
M***Z2101 天前
SQL 建表语句详解
java·数据库·sql
v***7941 天前
Spring Boot 热部署
java·spring boot·后端