ZhangXianQiang
2024-07-04 d77ff074e895d16b99f72386dd50655500cdb435
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<template>
  <div class="pdf-container">
    <iframe :src="fileUrl" width="100%" height="100%"></iframe>
  </div>
</template>
 
<script setup>
import { ref, onMounted } from 'vue';
 
const props = defineProps({
  pdfUrl: {
    type: String,
    required: true
  }
});
const viewerUrl = '/pdfjs/web/viewer.html?file='; // pdfjs文件地址
 
const fileUrl = ref('');
 
 
const renderPDF = () => {
  fileUrl.value = viewerUrl + encodeURIComponent(props.pdfUrl);
};
 
onMounted(() => {
  renderPDF();
})
 
</script>
 
<style lang="scss" scoped>
.pdf-container {
  width: 100%;
  height: 100%;
 
  .pdf-canvas {
    width: 100%;
    height: 100%;
  }
}
</style>