index.vue 1.2 KB
Newer Older
S
Sam Rose 已提交
1
<script>
2 3 4 5 6
export default {
  props: {
    page: {
      type: Object,
      required: true,
S
Sam Rose 已提交
7
    },
8 9 10 11 12 13 14 15 16 17 18 19 20 21
    number: {
      type: Number,
      required: true,
    },
  },
  data() {
    return {
      scale: 4,
      rendering: false,
    };
  },
  computed: {
    viewport() {
      return this.page.getViewport(this.scale);
S
Sam Rose 已提交
22
    },
23 24
    context() {
      return this.$refs.canvas.getContext('2d');
S
Sam Rose 已提交
25
    },
26 27 28 29 30
    renderContext() {
      return {
        canvasContext: this.context,
        viewport: this.viewport,
      };
S
Sam Rose 已提交
31
    },
32 33 34 35 36 37 38 39 40 41 42 43 44
  },
  mounted() {
    this.$refs.canvas.height = this.viewport.height;
    this.$refs.canvas.width = this.viewport.width;
    this.rendering = true;
    this.page
      .render(this.renderContext)
      .then(() => {
        this.rendering = false;
      })
      .catch(error => this.$emit('pdflaberror', error));
  },
};
S
Sam Rose 已提交
45 46
</script>

47 48 49
<template>
  <canvas
    ref="canvas"
F
Filipa Lacerda 已提交
50
    :data-page="number"
51
    class="pdf-page"
F
Filipa Lacerda 已提交
52 53
  >
  </canvas>
54 55
</template>

S
Sam Rose 已提交
56
<style>
57 58 59 60 61 62
.pdf-page {
  margin: 8px auto 0 auto;
  border-top: 1px #ddd solid;
  border-bottom: 1px #ddd solid;
  width: 100%;
}
S
Sam Rose 已提交
63

64 65 66 67
.pdf-page:first-child {
  margin-top: 0px;
  border-top: 0px;
}
S
Sam Rose 已提交
68

69 70 71 72
.pdf-page:last-child {
  margin-bottom: 0px;
  border-bottom: 0px;
}
S
Sam Rose 已提交
73
</style>