VUE pdf.js 打开 pdf流文件

pdf.js插件官网

1、文件下载后,放在 static文件目录下,新建 pdf 文件夹。

   openPDF(item) {
      const url = `${api}/api/order/orderItemLogistics/pdf/viewOrDownload?orderId=${item.orderId}&fileName=电子运单&type=1`
     const pdfUrl = './static/pdf/web/viewer.html?file=' + encodeURIComponent(url)
      window.open(pdfUrl)
    }

2、当viewer.html页面的域和pdf文件域不一致的时候,会报 “file origin does not match viewer”错误,我是通过注销viewer.js中的源码解决的。

 if (origin !== viewerOrigin && protocol !== "blob:") {
        // throw new Error("file origin does not match viewer's"); // 注销
      }

参考

你可能感兴趣的:(VUE pdf.js 打开 pdf流文件)