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

相关文章

基于 Cursor 开发 Spring Boot 项目详细攻略

《基于Cursor开发SpringBoot项目详细攻略》Cursor是集成GPT4、Claude3.5等LLM的VSCode类AI编程工具,支持SpringBoot项目开发全流程,涵盖环境配... 目录cursor是什么?基于 Cursor 开发 Spring Boot 项目完整指南1. 环境准备2. 创建

Vue和React受控组件的区别小结

《Vue和React受控组件的区别小结》本文主要介绍了Vue和React受控组件的区别小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学... 目录背景React 的实现vue3 的实现写法一:直接修改事件参数写法二:通过ref引用 DOMVu

Java实现将HTML文件与字符串转换为图片

《Java实现将HTML文件与字符串转换为图片》在Java开发中,我们经常会遇到将HTML内容转换为图片的需求,本文小编就来和大家详细讲讲如何使用FreeSpire.DocforJava库来实现这一功... 目录前言核心实现:html 转图片完整代码场景 1:转换本地 HTML 文件为图片场景 2:转换 H

C#使用Spire.Doc for .NET实现HTML转Word的高效方案

《C#使用Spire.Docfor.NET实现HTML转Word的高效方案》在Web开发中,HTML内容的生成与处理是高频需求,然而,当用户需要将HTML页面或动态生成的HTML字符串转换为Wor... 目录引言一、html转Word的典型场景与挑战二、用 Spire.Doc 实现 HTML 转 Word1

C#实现一键批量合并PDF文档

《C#实现一键批量合并PDF文档》这篇文章主要为大家详细介绍了如何使用C#实现一键批量合并PDF文档功能,文中的示例代码简洁易懂,感兴趣的小伙伴可以跟随小编一起学习一下... 目录前言效果展示功能实现1、添加文件2、文件分组(书签)3、定义页码范围4、自定义显示5、定义页面尺寸6、PDF批量合并7、其他方法

Vue3绑定props默认值问题

《Vue3绑定props默认值问题》使用Vue3的defineProps配合TypeScript的interface定义props类型,并通过withDefaults设置默认值,使组件能安全访问传入的... 目录前言步骤步骤1:使用 defineProps 定义 Props步骤2:设置默认值总结前言使用T

Three.js构建一个 3D 商品展示空间完整实战项目

《Three.js构建一个3D商品展示空间完整实战项目》Three.js是一个强大的JavaScript库,专用于在Web浏览器中创建3D图形,:本文主要介绍Three.js构建一个3D商品展... 目录引言项目核心技术1. 项目架构与资源组织2. 多模型切换、交互热点绑定3. 移动端适配与帧率优化4. 可

sky-take-out项目中Redis的使用示例详解

《sky-take-out项目中Redis的使用示例详解》SpringCache是Spring的缓存抽象层,通过注解简化缓存管理,支持Redis等提供者,适用于方法结果缓存、更新和删除操作,但无法实现... 目录Spring Cache主要特性核心注解1.@Cacheable2.@CachePut3.@Ca

基于C#实现PDF转图片的详细教程

《基于C#实现PDF转图片的详细教程》在数字化办公场景中,PDF文件的可视化处理需求日益增长,本文将围绕Spire.PDFfor.NET这一工具,详解如何通过C#将PDF转换为JPG、PNG等主流图片... 目录引言一、组件部署二、快速入门:PDF 转图片的核心 C# 代码三、分辨率设置 - 清晰度的决定因

Python自动化处理PDF文档的操作完整指南

《Python自动化处理PDF文档的操作完整指南》在办公自动化中,PDF文档处理是一项常见需求,本文将介绍如何使用Python实现PDF文档的自动化处理,感兴趣的小伙伴可以跟随小编一起学习一下... 目录使用pymupdf读写PDF文件基本概念安装pymupdf提取文本内容提取图像添加水印使用pdfplum