gitlab-org--gitlab-foss/app/assets/javascripts/pdf/page/index.vue
Stan Hu c34138e09e Remove pdf.js deprecation warnings
1. `page.getViewpoint()` now takes in JSON instead of an integer.
2. Promises are returned from loading and rendering tasks.

See https://mozilla.github.io/pdf.js/examples/index.html for more
details.
2019-07-30 06:52:56 -07:00

70 lines
1.2 KiB
Vue

<script>
export default {
props: {
page: {
type: Object,
required: true,
},
number: {
type: Number,
required: true,
},
},
data() {
return {
scale: 4,
rendering: false,
};
},
computed: {
viewport() {
return this.page.getViewport({ scale: this.scale });
},
context() {
return this.$refs.canvas.getContext('2d');
},
renderContext() {
return {
canvasContext: this.context,
viewport: this.viewport,
};
},
},
mounted() {
this.$refs.canvas.height = this.viewport.height;
this.$refs.canvas.width = this.viewport.width;
this.rendering = true;
this.page
.render(this.renderContext)
.promise.then(() => {
this.rendering = false;
})
.catch(error => {
this.$emit('pdflaberror', error);
});
},
};
</script>
<template>
<canvas ref="canvas" :data-page="number" class="pdf-page"> </canvas>
</template>
<style>
.pdf-page {
margin: 8px auto 0 auto;
border-top: 1px #ddd solid;
border-bottom: 1px #ddd solid;
width: 100%;
}
.pdf-page:first-child {
margin-top: 0px;
border-top: 0px;
}
.pdf-page:last-child {
margin-bottom: 0px;
border-bottom: 0px;
}
</style>