vue h5项目预览pdf文件+电子签名

2024-05-14 05:28

本文主要是介绍vue h5项目预览pdf文件+电子签名,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

vue h5项目预览pdf文件+电子签名

1、vue安装pdfh5

npm install pdfh5

2、示例代码
pdf文件预览页面

<template><div class="pdf-container><div id="pdfView"></div><div v-if="SignPanelShow=='0'" class="pdfbtn" @click="openSignPanel">签名</div><!-- 手签版弹出层--><van-popup class="popup" v-model="signPopup" position="bottom" :style="{ height: '50%' }" closeable><div class="popup-title">请手签您的姓名全称</div><div class="popup-content"><canvas isee_sign ref="signCanvas"></canvas></div><div class="popup-panel"><van-cell><van-button type="default" style="width: 49%;" @click="clear">清除</van-button><van-button type="info" style="width: 49%;" @click="saveImageInfo">确认</van-button></van-cell></div></van-popup></div></template>

js部分

 <script>import Pdfh5 from "pdfh5";import { initCanvas, clearArea } from '../assets/js/canvas.js';export default {name: 'App',data() {return {pdfh5: null,SignPanelShow:'', // 签字状态signPopup: false,/** 手签版校验 */drawed: false,uuid: '',};},components: {pdf,},mounted() {let o = this.getParam();this.uuid = o.uuid;// 获取pdf文件this.querypdf()// 获取签字状态this.getsignpanetype()},methods:{// 获取地址栏参数getParam() {var urlStr = location.href;if (typeof urlStr == "undefined") {var url = decodeURI(location.search); //获取url中"?"符后的字符串} else {var url = "?" + urlStr.split("?")[1];}var theRequest = new Object();if (url.indexOf("?") != -1) {var str = url.substr(1);var strs = str.split("&");for (var i = 0; i < strs.length; i++) {theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);}}return theRequest;},querypdf(){this.$axios({url:"api/propertyServer/view/"+ this.uuid,method:"get",//get请求方式params:'', //传给后台的参数responseType: 'blob'}).then(res=>{console.log('pdf',res)if(res.status ==200){this.pdfh5 = new Pdfh5("#pdfView", {pdfurl: window.URL.createObjectURL(new Blob([res.data])),zoomEnable:false, // 是否允许pdf手势缩放});}}).catch(error=>{});},getsignpanetype(){this.$axios({url:'api/propertyServer/Status/' + this.uuid,method:"get",//get请求方式}).then(res=>{if(res.status ==200){this.SignPanelShow = res.data}console.log('签字状态',res,res.data)}).catch(error=>{});},// 打开签字板openSignPanel: function () {this.signPopup = truethis.$nextTick(() => { initCanvas(this) })},// 清空签字clear: function () {clearArea(this)this.drawed = false},// 签字确认saveImageInfo(){if (!this.drawed) {this.$toast.fail('请签字')return}this.$toast.loading({duration: 0, forbidClick: true, message: '正在加载', overlay: true})this.signPopup = falsethis.$axios({url:"api/propertyServer/sign/"+ this.uuid,method:"post",data:{image:this.canvas.toDataURL()},}).then(res=>{if(res.status ==200){// 更新签字状态this.getsignpanetype()this.$toast.clear()}}).catch(error=>{});}       }}</script>

css部分

<style >@import "pdfh5/css/pdfh5.css";*{padding: 0;margin: 0;}html,body,#app {width: 100%;height: 100%;padding-bottom: 7px;box-sizing: border-box;}
</style><style scoped>.pdf-container{width: 100%;height: 100vh;}/* 签字按钮 */.pdfbtn{width: 100%;height: 45px;position: fixed;left: 0;bottom: 0;font-size: 18px;color: #fff;background-color: rgb(69, 135, 246);text-align: center;line-height: 45px;}/* 客户签字版 弹出层 */.popup {display: flex;flex-direction: column;overflow-y: auto;}.popup-title {font-size: 20px;font-weight: 600;text-align: center;margin-top: 20px;}.popup-content {overflow-y: hidden;height: 70%;}</style>

签字板canvas.js

/** 初始化canvas画布 */
export const initCanvas = that => {/** canvas初始化 */let canvas = that.$refs.signCanvasthat.canvas = canvasthat.ctx = canvas.getContext('2d')let winW = window.innerWidthlet winH = window.innerHeight / 3canvas.width = winWcanvas.height = winH/** 按下屏幕事件 */that.canvas.addEventListener('touchstart',(event) => {if (event.targetTouches.length === 1) {const offset = (window.innerHeight / 2) // 起始偏移量由canvas画布在屏幕中的位置决定 这里是50%event.preventDefault() // 阻止浏览器默认事件,重要var touch = event.targetTouches[0]that.touchPressed = truedraw(touch.pageX - that.canvas.offsetLeft, touch.pageY - that.canvas.offsetTop - offset, false, that)}}, false)/** 拖动屏幕事件 */that.canvas.addEventListener('touchmove',(event) => {if (event.targetTouches.length === 1) {const offset = (window.innerHeight / 2) // 起始偏移量由canvas画布在屏幕中的位置决定 这里是50%event.preventDefault() // 阻止浏览器默认事件,重要var touch = event.targetTouches[0]if (that.touchPressed) {draw(touch.pageX - that.canvas.offsetLeft, touch.pageY - that.canvas.offsetTop - offset, true, that)}}}, false)/** 结束拖动屏幕事件 */that.canvas.addEventListener('touchend',(event) => {if (event.targetTouches.length === 1) {event.preventDefault() // 阻止浏览器默认事件,防止手写的时候拖动屏幕,重要that.touchPressed = false}that.drawed = true}, false)
}/** 根据坐标与偏移量绘制图案 */
function draw (x, y, isDown, that) {let ctx = that.ctxif (isDown) {ctx.beginPath()ctx.strokeStyle = that.strokeStylectx.lineWidth = that.lineWidthctx.lineJoin = 'round'ctx.moveTo(that.lastX, that.lastY)ctx.lineTo(x, y)ctx.closePath()ctx.stroke()}that.lastX = xthat.lastY = y
}/** 清空画板 */
export const clearArea = that => {that.ctx.setTransform(1, 0, 0, 1, 0, 0)that.ctx.clearRect(0, 0, that.ctx.canvas.width, that.ctx.canvas.height)
}

参考文章链接 https://pdfh5.gjtool.cn/#/pages/index/detail?id=646781ec0c801ca87845c820

这篇关于vue h5项目预览pdf文件+电子签名的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/987862

相关文章

使用Python将PDF表格自动提取并写入Word文档表格

《使用Python将PDF表格自动提取并写入Word文档表格》在实际办公与数据处理场景中,PDF文件里的表格往往无法直接复制到Word中,本文将介绍如何使用Python从PDF文件中提取表格数据,并将... 目录引言1. 加载 PDF 文件并准备 Word 文档2. 提取 PDF 表格并创建 Word 表格

HTML5的input标签的`type`属性值详解和代码示例

《HTML5的input标签的`type`属性值详解和代码示例》HTML5的`input`标签提供了多种`type`属性值,用于创建不同类型的输入控件,满足用户输入的多样化需求,从文本输入、密码输入、... 目录一、引言二、文本类输入类型2.1 text2.2 password2.3 textarea(严格

JAVA项目swing转javafx语法规则以及示例代码

《JAVA项目swing转javafx语法规则以及示例代码》:本文主要介绍JAVA项目swing转javafx语法规则以及示例代码的相关资料,文中详细讲解了主类继承、窗口创建、布局管理、控件替换、... 目录最常用的“一行换一行”速查表(直接全局替换)实际转换示例(JFramejs → JavaFX)迁移建

JavaWeb项目创建、部署、连接数据库保姆级教程(tomcat)

《JavaWeb项目创建、部署、连接数据库保姆级教程(tomcat)》:本文主要介绍如何在IntelliJIDEA2020.1中创建和部署一个JavaWeb项目,包括创建项目、配置Tomcat服务... 目录简介:一、创建项目二、tomcat部署1、将tomcat解压在一个自己找得到路径2、在idea中添加

解决idea启动项目报错java: OutOfMemoryError: insufficient memory

《解决idea启动项目报错java:OutOfMemoryError:insufficientmemory》:本文主要介绍解决idea启动项目报错java:OutOfMemoryError... 目录原因:解决:总结 原因:在Java中遇到OutOfMemoryError: insufficient me

SpringBoot返回文件让前端下载的几种方式

《SpringBoot返回文件让前端下载的几种方式》文章介绍了开发中文件下载的两种常见解决方案,并详细描述了通过后端进行下载的原理和步骤,包括一次性读取到内存和分块写入响应输出流两种方法,此外,还提供... 目录01 背景02 一次性读取到内存,通过响应输出流输出到前端02 将文件流通过循环写入到响应输出流

python项目环境切换的几种实现方式

《python项目环境切换的几种实现方式》本文主要介绍了python项目环境切换的几种实现方式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1. 如何在不同python项目中,安装不同的依赖2. 如何切换到不同项目的工作空间3.创建项目

SpringBoot项目整合Netty启动失败的常见错误总结

《SpringBoot项目整合Netty启动失败的常见错误总结》本文总结了SpringBoot集成Netty时常见的8类问题及解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参... 目录一、端口冲突问题1. Tomcat与Netty端口冲突二、主线程被阻塞问题1. Netty启动阻

python项目打包成docker容器镜像的两种方法实现

《python项目打包成docker容器镜像的两种方法实现》本文介绍两种将Python项目打包为Docker镜像的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 目录简单版:(一次成功,后续下载对应的软件依赖)第一步:肯定是构建dockerfile,如下:第二步

Python + Streamlit项目部署方案超详细教程(非Docker版)

《Python+Streamlit项目部署方案超详细教程(非Docker版)》Streamlit是一款强大的Python框架,专为机器学习及数据可视化打造,:本文主要介绍Python+St... 目录一、针对 Alibaba Cloud linux/Centos 系统的完整部署方案1. 服务器基础配置(阿里