pdf.js ie11兼容问题

2020-10-22  本文已影响0人  周郭郭先生

关于PDF.js IE11不显示问题解决方案

以下注意点

1、版本只能选择2.0.943稳定版(vue为例)

package.json中添加

   "pdfjs-dist": "2.0.943",

2、代码调用

<template>
  <div class="home">
    <canvas id="the-canvas"></canvas>
  </div>
</template>

<script>

const PDF = require('pdfjs-dist');
import pdfjsWorker from 'pdfjs-dist/build/pdf.worker.entry';
PDF.GlobalWorkerOptions.workerSrc = pdfjsWorker;
export default {
  name: 'Home',
  components: {},
  data() {
    return {
     
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      var loadingTask = 'http://storage.xuetangx.com/public_assets/xuetangx/PDF/PlayerAPI_v1.0.6.pdf'
      PDF.getDocument(loadingTask).then((pdf) => {
        pdf.getPage(1).then(function(page) {
          var viewport = page.getViewport(1.5);
          var canvas = document.getElementById('the-canvas');
          var context = canvas.getContext('2d');
          canvas.height = viewport.height;
          canvas.width = viewport.width;
          var renderContext = {
            canvasContext: context,
            viewport: viewport,
          };
          page.render(renderContext);
        });
      });
    },
  },
};
</script>
上一篇下一篇

猜你喜欢

热点阅读