美文网首页
pdf.js ie11兼容问题

pdf.js ie11兼容问题

作者: 周郭郭先生 | 来源:发表于2020-10-22 15:35 被阅读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>
    

    相关文章

      网友评论

          本文标题:pdf.js ie11兼容问题

          本文链接:https://www.haomeiwen.com/subject/pfxpmktx.html