处理后端返回的pdf的文件流后预览

2020-12-16  本文已影响0人  PharkiLL
// 需要安装 vue-pdf插件
 import pdf from 'vue-pdf';
 // pdf 预览
getPdfUrl() {
        if(this.formData.businessTicketFrontPath) {
          getImgUrl(this.formData.businessTicketFrontPath).then(res=>{
            console.log('res:',res);
            this.pdfVisible = true;
            const {data, header} = res
            const blob = new Blob([data])
            let url = window.URL.createObjectURL(blob)
            this.getNumPages(url)
          })
        }
      },
getNumPages(pdfUrl) {
        var loadingTask = pdf.createLoadingTask(pdfUrl)
        loadingTask.promise.then(pdf => {
          this.pdfUrl = loadingTask
          this.numPages = pdf.numPages
        }).catch((err) => {
          console.error('pdf加载失败')
        })
 },
上一篇 下一篇

猜你喜欢

热点阅读