简介:pdfh5是比较简单实现预览pdf的插件,react、vue均可使用;
一、Demo移动端效果展示:可监听滑动位置、页码、指定页码等方法;

二、用法:
- npm 安装依赖:npm install pdfh5
- vue组件应用:
import PdfShow from './component/PdfShow.vue'
components: {
PdfShow
}
<div id="app">
<pdf-show ref="PreviewpdfH5"></pdf-show>
</div>
<template>
<div id="app">
<div id="demo"></div>
</div>
</template>
<script>
import Pdfh5 from "pdfh5";
export default {
name: 'App',
data() {
return {
pdfh5: null
};
},
mounted() {
this.pdfh5 = new Pdfh5("#demo", {
pdfurl: "../../static/test.pdf"
});
let that = this;
this.pdfh5.on("complete", function (status, msg, time) {
that.totalNum = this.totalNum
console.log("状态:" + status + ",信息:" + msg + ",耗时:" + time + "毫秒,总页数:" + this.totalNum)
});
this.pdfh5.on("scroll", function (scrollTop, currentNum) {
console.log(scrollTop, currentNum)
});
}
}
</script>
<style>
@import "pdfh5/css/pdfh5.css";
*{
padding: 0;
margin: 0;
}
html,body,#app {
width: 100%;
height: 100%;
}
</style>