debian-mirror-gitlab/app/assets/javascripts/pdf/page/index.vue

71 lines
1.2 KiB
Vue
Raw Normal View History

2017-08-17 22:00:37 +05:30
<script>
2018-12-13 13:39:08 +05:30
export default {
props: {
page: {
type: Object,
required: true,
2017-08-17 22:00:37 +05:30
},
2018-12-13 13:39:08 +05:30
number: {
type: Number,
required: true,
},
},
data() {
return {
scale: 4,
rendering: false,
};
},
computed: {
viewport() {
2019-10-12 21:52:04 +05:30
return this.page.getViewport({ scale: this.scale });
2017-08-17 22:00:37 +05:30
},
2018-12-13 13:39:08 +05:30
context() {
return this.$refs.canvas.getContext('2d');
2017-08-17 22:00:37 +05:30
},
2018-12-13 13:39:08 +05:30
renderContext() {
return {
canvasContext: this.context,
viewport: this.viewport,
};
2017-08-17 22:00:37 +05:30
},
2018-12-13 13:39:08 +05:30
},
mounted() {
this.$refs.canvas.height = this.viewport.height;
this.$refs.canvas.width = this.viewport.width;
this.rendering = true;
this.page
.render(this.renderContext)
2019-10-12 21:52:04 +05:30
.promise.then(() => {
2018-12-13 13:39:08 +05:30
this.rendering = false;
})
2019-09-30 21:07:59 +05:30
.catch(error => {
this.$emit('pdflaberror', error);
});
2018-12-13 13:39:08 +05:30
},
};
2017-08-17 22:00:37 +05:30
</script>
2018-03-17 18:26:18 +05:30
<template>
2019-02-15 15:39:39 +05:30
<canvas ref="canvas" :data-page="number" class="pdf-page"> </canvas>
2018-03-17 18:26:18 +05:30
</template>
2017-08-17 22:00:37 +05:30
<style>
2018-12-13 13:39:08 +05:30
.pdf-page {
margin: 8px auto 0 auto;
border-top: 1px #ddd solid;
border-bottom: 1px #ddd solid;
width: 100%;
}
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
.pdf-page:first-child {
margin-top: 0px;
border-top: 0px;
}
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
.pdf-page:last-child {
margin-bottom: 0px;
border-bottom: 0px;
}
2017-08-17 22:00:37 +05:30
</style>