我准备实现pdfjs预览pdf文件,然后就用到了以下代码。
https://域名1/static/pdf/web/viewer.html是pdfjs的模板文件(我是把官网给的文件下载后放在域名根目录,达到减小项目本身的大小的目的);
https://域名2/static/U57%E8%8B%B1%E6%96%87%E7%89%88.pdf则是我想要预览的文件(这个文件是放在七牛云文件服务器上的)。
然后我通过http://localhost:8080访问这个页面的确正常显示了pdf文件,没有报错,但是从微信小程序开发工具和体验版都没法打开,显示空白且控制台没报错。请问这是什么原因呢?有什么解决思路吗?
<iframe
frameBorder="no"
allowfullscreen="true"
scrolling="no"
width="100%"
height="800"
src="https://域名/static/pdf/web/viewer.html?file=https://域名/static/U57%E8%8B%B1%E6%96%87%E7%89%88.pdf"
></iframe>
降低版本就好使了,我2.15降低到2.4的就好使了
我也是用的2.4.456版本,后面加file还是不能加载出来。
```http://127.0.0.1:5500/web/viewer.html?file=https://xxxx.oss-cn-zhangjiakou.aliyuncs.com/20221111/10310439557.pdf```
报错显示
```
file origin does not match viewer's
```
解决了。就是把这段代码注释掉(viewer.js)
```
if (origin !== viewerOrigin && protocol !== "blob:") {
throw new Error("file origin does not match viewer's");
}
```
我用2.9版本的pdfjs不能显示,后面降到2.4版本就能显示出来了。在qq浏览器里面报错,估计是某些语法不支持。或者build下js再使用
求问,有解决了吗?
遇到同样问题,有解决了吗