1.下载pdfjs
官网:
http://mozilla.github.io/pdf.js/getting_started/#download
2.放在项目中位置
将下载下来的文件解压,放在项目的public目录下
3.在页面中使用
在我的项目中,pdf文件是以url的形式提供的,我们在页面中放一个iframe,他的src属性等于到viewer.html的相对路径 ‘/pdfplugin/web/viewer.html?file=’ ,file后拼接你的pdf的url就可以了。
<template>
<div>
<iframe :src="src" style="width: 100%;height: 100vh" ></iframe>
</div>
</template>
<script>
export default {
name: "myTestTwo",
data(){
return {
url:'http://storage.xuetangx.com/public_assets/xuetangx/PDF/PlayerAPI_v1.0.6.pdf',
src:''
}
},
mounted() {
this.getUrl();
},
methods :{
getUrl:function () {
this.src = '/pdfplugin/web/viewer.html?file=' + this.url
}
}
}
</script>
<style scoped>
</style>