1、肯定是先安装了:
npm i pdfobject --save
2、引入
import pdf from 'pdfobject'
<template>
<div>
<p class="over" />
<div id="pdf-content">
<el-container class="container" @contextmenu.native="handlePaste($event)" />
</div>
</div>
</template>
<script>
import pdf from 'pdfobject'
import {
GetStudentExaminationBuild
} from '@/api/student_examination'
export default {
name: 'ViewPDF',
props: {
pdfUrl: {
type: String,
default: ''
}
},
data() {
return {
id: '',
PdfWebPath: '',
pdfTop: 40,
showTips: true
}
},
created() {
// 禁止选择网页中的文字
document.onselectstart = function() {
return false
}
// 禁止鼠标右键功能
document.oncontextmenu = function() {
return false
}
var query = this.$route.query
this.id = query.id
if (query.type == 'stuent_examination') {
GetStudentExaminationBuild({
id: this.id
}).then(response => {
// alert(response.WebPath)
var options = {
height: '10000px',
pdfOpenParams: {
scrollbars: '0',
toolbar: '0',
statusbar: '0'
} // 禁用工具栏代码
}
pdf.embed(response.WebPath,
'#pdf-content', options)
})
}
},
mounted() {
// this.PdfWebPath = query.bean.studentExaminationBuild.webPath
},
methods: {
handlePaste(event) {
// 禁用鼠标右键
event.preventDefault()
return false
}
}
// beforeMount() {
// var that = this;
// that.$nextTick(function() {
// pdf.embed(that.pdfUrl, "#pdf-content");
// })
// },
}
</script>
<style>
#pdf{
width:100%;
height: 100%;
margin: 0;
padding: 0;
}
.over{
width:100%;
height: 100%;
background-color: rgba(1,1,1,0);
position: fixed;
top:0px;
left:0px;
}
</style>