summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pdf/page/index.vue
blob: 65f84e75e86cba4232955645d261b1d4a14c6035 (plain)
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
<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>