移动端pdf在线预览(pdfh5.js插件版)
- 安装(适应于vue)
npm install pdfh5
- 使用(适应于vue)
<template>
<div class="m-pdf">
<div id="pdf"></div>
</div>
</template>
<script>
import Pdfh5 from "pdfh5";
import "pdfh5/css/pdfh5.css";
export default {
name: "Index",
data() {
return {
pdfh5: null,
pdfUrl: "http://localhost:9000/1.pdf",
};
},
mounted() {
this.pdfh5 = new Pdfh5("#pdf", {
pdfurl: this.pdfUrl,
goto: 1,
});
this.pdfh5.on("ready", function () {
console.log("总页数:" + this.totalNum);
});
this.pdfh5.on("complete", (status, msg, time) => {
console.log(
"状态:" + status + ",信息:" + msg + ",耗时:" + time + "毫秒"
);
});
},
};
</script>
<style lang="scss">
.m-pdf {
position: fixed;
top: 30px;
bottom: 30px;
right: 0;
left: 0;
}
</style>