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

相关文章

深度解析Java项目中包和包之间的联系

《深度解析Java项目中包和包之间的联系》文章浏览阅读850次,点赞13次,收藏8次。本文详细介绍了Java分层架构中的几个关键包:DTO、Controller、Service和Mapper。_jav... 目录前言一、各大包1.DTO1.1、DTO的核心用途1.2. DTO与实体类(Entity)的区别1

如何在Spring Boot项目中集成MQTT协议

《如何在SpringBoot项目中集成MQTT协议》本文介绍在SpringBoot中集成MQTT的步骤,包括安装Broker、添加EclipsePaho依赖、配置连接参数、实现消息发布订阅、测试接口... 目录1. 准备工作2. 引入依赖3. 配置MQTT连接4. 创建MQTT配置类5. 实现消息发布与订阅

springboot项目打jar制作成镜像并指定配置文件位置方式

《springboot项目打jar制作成镜像并指定配置文件位置方式》:本文主要介绍springboot项目打jar制作成镜像并指定配置文件位置方式,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录一、上传jar到服务器二、编写dockerfile三、新建对应配置文件所存放的数据卷目录四、将配置文

前端如何通过nginx访问本地端口

《前端如何通过nginx访问本地端口》:本文主要介绍前端如何通过nginx访问本地端口的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、nginx安装1、下载(1)下载地址(2)系统选择(3)版本选择2、安装部署(1)解压(2)配置文件修改(3)启动(4)

怎么用idea创建一个SpringBoot项目

《怎么用idea创建一个SpringBoot项目》本文介绍了在IDEA中创建SpringBoot项目的步骤,包括环境准备(JDK1.8+、Maven3.2.5+)、使用SpringInitializr... 目录如何在idea中创建一个SpringBoot项目环境准备1.1打开IDEA,点击New新建一个项

HTML中meta标签的常见使用案例(示例详解)

《HTML中meta标签的常见使用案例(示例详解)》HTMLmeta标签用于提供文档元数据,涵盖字符编码、SEO优化、社交媒体集成、移动设备适配、浏览器控制及安全隐私设置,优化页面显示与搜索引擎索引... 目录html中meta标签的常见使用案例一、基础功能二、搜索引擎优化(seo)三、社交媒体集成四、移动

HTML input 标签示例详解

《HTMLinput标签示例详解》input标签主要用于接收用户的输入,随type属性值的不同,变换其具体功能,本文通过实例图文并茂的形式给大家介绍HTMLinput标签,感兴趣的朋友一... 目录通用属性输入框单行文本输入框 text密码输入框 password数字输入框 number电子邮件输入编程框

HTML img标签和超链接标签详细介绍

《HTMLimg标签和超链接标签详细介绍》:本文主要介绍了HTML中img标签的使用,包括src属性(指定图片路径)、相对/绝对路径区别、alt替代文本、title提示、宽高控制及边框设置等,详细内容请阅读本文,希望能对你有所帮助... 目录img 标签src 属性alt 属性title 属性width/h

CSS3打造的现代交互式登录界面详细实现过程

《CSS3打造的现代交互式登录界面详细实现过程》本文介绍CSS3和jQuery在登录界面设计中的应用,涵盖动画、选择器、自定义字体及盒模型技术,提升界面美观与交互性,同时优化性能和可访问性,感兴趣的朋... 目录1. css3用户登录界面设计概述1.1 用户界面设计的重要性1.2 CSS3的新特性与优势1.

HTML5 中的<button>标签用法和特征

《HTML5中的<button>标签用法和特征》在HTML5中,button标签用于定义一个可点击的按钮,它是创建交互式网页的重要元素之一,本文将深入解析HTML5中的button标签,详细介绍其属... 目录引言<button> 标签的基本用法<button> 标签的属性typevaluedisabled