-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPDFPage.vue
74 lines (70 loc) · 1.28 KB
/
PDFPage.vue
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<template>
<canvas ref="canvas" />
</template>
<script>
export default {
name: 'PDFPage',
props: {
page: {
type: Promise,
},
scale: {
type: Number,
default: 1,
},
},
data() {
return {
dynamicScale: this.scale,
// canvas:null,
// width:null,
// height:null,
clientWidth: null,
}
},
watch: {
page(){
this.render()
},
scale(newScale) {
this.dynamicScale = newScale // Monitor changes in the scale attribute and update dynamic scaling
this.render()
},
},
mounted() {
this.render()
},
methods: {
getCanvasMeasurement() {
return {
canvasWidth: this.$refs.canvas.width,
canvasHeight: this.$refs.canvas.height,
}
},
measure() {
this.$emit('onMeasure', {
scale: this.dynamicScale,
})
},
async render() {
const _page = await this.page
if(typeof _page ==='undefined') return
const canvas = this.$refs.canvas
const context = canvas.getContext('2d')
const viewport = _page.getViewport({
scale: this.dynamicScale,
rotation: 0,
})
canvas.width = viewport.width
canvas.height = viewport.height
await _page.render({
canvasContext: context,
viewport,
}).promise
this.measure()
window.addEventListener('resize', this.measure)
},
},
}
</script>
<style scoped></style>