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

相关文章

解决Maven项目报错:failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0的问题

《解决Maven项目报错:failedtoexecutegoalorg.apache.maven.plugins:maven-compiler-plugin:3.13.0的问题》这篇文章主要介... 目录Maven项目报错:failed to execute goal org.apache.maven.pl

在.NET平台使用C#为PDF添加各种类型的表单域的方法

《在.NET平台使用C#为PDF添加各种类型的表单域的方法》在日常办公系统开发中,涉及PDF处理相关的开发时,生成可填写的PDF表单是一种常见需求,与静态PDF不同,带有**表单域的文档支持用户直接在... 目录引言使用 PdfTextBoxField 添加文本输入域使用 PdfComboBoxField

Python开发文字版随机事件游戏的项目实例

《Python开发文字版随机事件游戏的项目实例》随机事件游戏是一种通过生成不可预测的事件来增强游戏体验的类型,在这篇博文中,我们将使用Python开发一款文字版随机事件游戏,通过这个项目,读者不仅能够... 目录项目概述2.1 游戏概念2.2 游戏特色2.3 目标玩家群体技术选择与环境准备3.1 开发环境3

SpringBoot项目中报错The field screenShot exceeds its maximum permitted size of 1048576 bytes.的问题及解决

《SpringBoot项目中报错ThefieldscreenShotexceedsitsmaximumpermittedsizeof1048576bytes.的问题及解决》这篇文章... 目录项目场景问题描述原因分析解决方案总结项目场景javascript提示:项目相关背景:项目场景:基于Spring

解决Maven项目idea找不到本地仓库jar包问题以及使用mvn install:install-file

《解决Maven项目idea找不到本地仓库jar包问题以及使用mvninstall:install-file》:本文主要介绍解决Maven项目idea找不到本地仓库jar包问题以及使用mvnin... 目录Maven项目idea找不到本地仓库jar包以及使用mvn install:install-file基

Android实现在线预览office文档的示例详解

《Android实现在线预览office文档的示例详解》在移动端展示在线Office文档(如Word、Excel、PPT)是一项常见需求,这篇文章为大家重点介绍了两种方案的实现方法,希望对大家有一定的... 目录一、项目概述二、相关技术知识三、实现思路3.1 方案一:WebView + Office Onl

springboot项目如何开启https服务

《springboot项目如何开启https服务》:本文主要介绍springboot项目如何开启https服务方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录springboot项目开启https服务1. 生成SSL证书密钥库使用keytool生成自签名证书将

HTML5中的Microdata与历史记录管理详解

《HTML5中的Microdata与历史记录管理详解》Microdata作为HTML5新增的一个特性,它允许开发者在HTML文档中添加更多的语义信息,以便于搜索引擎和浏览器更好地理解页面内容,本文将探... 目录html5中的Mijscrodata与历史记录管理背景简介html5中的Microdata使用M

html5的响应式布局的方法示例详解

《html5的响应式布局的方法示例详解》:本文主要介绍了HTML5中使用媒体查询和Flexbox进行响应式布局的方法,简要介绍了CSSGrid布局的基础知识和如何实现自动换行的网格布局,详细内容请阅读本文,希望能对你有所帮助... 一 使用媒体查询响应式布局        使用的参数@media这是常用的

HTML5表格语法格式详解

《HTML5表格语法格式详解》在HTML语法中,表格主要通过table、tr和td3个标签构成,本文通过实例代码讲解HTML5表格语法格式,感兴趣的朋友一起看看吧... 目录一、表格1.表格语法格式2.表格属性 3.例子二、不规则表格1.跨行2.跨列3.例子一、表格在html语法中,表格主要通过< tab