fxxqq / 6fedcom.github.io

frank的前端养成记(hexo博客)
https://6fed.com
22 stars 5 forks source link

PDF.js访问远程服务器报file origin does not match viewer's #71

Open fxxqq opened 6 years ago

fxxqq commented 6 years ago

如果需要加载远程服务器的pdf文件,远程服务器返回pdf文件流,然后在viewer.html的url后面添加file=http://127.0.0.1:8020/PDF/test ,但是pdf.js不支持跨域请求,所以会报错:file origin does not match viewer’s,试了很多种方法仍然报错,所以简单粗暴的方法就是把viewer.js的判断远程地址的代码注释掉即可。

注释viewer.js的代码:

//    if (fileOrigin !== viewerOrigin) {
//      throw new Error('file origin does not match viewer\'s');
//    }

pdfjs预览demo https://ye63.github.io/pdfjs/web/index.html?pdf=https://teenagertestcdn.speakhi.com/courseware/one2many/course_type102/7c12c2ab54904b758e56ad104c47ddd3.pdf

github地址:https://github.com/ye63/pdfjs