-
npm i pdfh5 -s
-
import Pdfh5 from "pdfh5";
import "pdfh5/css/pdfh5.css";
-
html中使用如下:
<div id="pdf-content" style="height:100%;width:100%;"></div>
-
代码中使用如下:
initPdf() { // pdfh5实例化时传两个参数:selector选择器,options配置项参数,会返回一个pdfh5实例对象, // 可以用来操作pdf,监听相关事件 // pdfh5 = new Pdfh5(selector, options) goto初始到第几页,logo设置每一页pdf上的水印 this.pdfh5 = new Pdfh5("#pdf-content", { pdfurl: this.pdfUrl, goto: 1, // 设置每一页pdf上的水印 // logo: { src: require("@/assets/images/icon27.png"), x: 20, y: 70, width: 60, height: 60 }, }); this.pdfh5.scrollEnable(true); // 允许pdf滚动 // 监听pdf准备开始渲染,此时可以拿到pdf总页数 this.pdfh5.on("ready", function () { console.log("总页数:" + this.totalNum); }); // 监听pdf加载完成事件,加载失败、渲染成功都会触发 this.pdfh5.on("complete", (status, msg, time) => { console.log("状态:" + status + ",信息:" + msg + ",耗时:" + time + "毫秒"); }); }, //自带的下载貌似不管用 this.pdfh5.download()
下载可利用浏览器访问的链接下载:
-
// 下载文件,自定义文件名称 downFile(url, fileName) { let ele = document.createElement('a') ele.download = fileName ele.style.display = 'none' ele.href = url document.body.appendChild(ele) ele.click() document.body.removeChild(ele) },
h5手机端pdf预览(可缩放)
最新推荐文章于 2024-06-03 17:52:58 发布