vue 中如何使用pdf.js实现预览

记录

(1)下载pdf.js文件

pdf.js文件

(2)在static中引入核心文件

 (2)使用

  <iframe  :src="pathUrl"  frameborder="0" scrolling="yes" ></iframe>
<script>
export default {
    data () {
       return {
         pathUrl:''
       }
     },
     mounted () {
      this.pathUrl = '../../../../static/pdf/web/viewer.html?file=' + encodeURIComponent(url)     // 找到之前引进来pdf文件中的的viewe.html并+pdf地址
    },
 }
</script>

备注:上线后预览不了一直404   后来直接this.pathUrl=url

(4)实现

 (5)问题

 (6)解决

引入的pdf.js文件中找到

  if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {

      return false;

    }

更换为

  if (fullRequestXhr.getAllResponseHeaders('Accept-Ranges') !== 'bytes') {
      return false;
    }


版权声明:本文为C_TopTopTop原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。