PDF.js的使用

1.下载pdf.js插件:点击下载
2.解压后把web和build文件夹放进项目里。
目录
3.新建一个test.html,通过iframe标签嵌套viewer.html即可,如果是只加载本地文件,在viewer.js修改默认的pdf文件路径即可。

<iframe src="web/viewer.html" width="100%" height="800px"></iframe>

修改viewer.js的默认的pdf的文件路径:

var DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf';

4.如果需要加载远程服务器的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的判断远程地址的代码注释掉即可。

<iframe src="web/viewer.html?file=http://127.0.0.1:8020/PDF/test" width="100%" height="800px"></iframe>

注释viewer.js的代码:

//    if (fileOrigin !== viewerOrigin) {
//      throw new Error('file origin does not match viewer\'s');
//    }
GitHub 加速计划 / pd / pdf.js
6
0
下载
PDF Reader in JavaScript
最近提交(Master分支:6 个月前 )
a857ca32 [Editor] Wait for switching to stamp mode before adding a new editor when dnd'ing an image 9 天前
9984afe6 When dnd'ing an image with the FreeText mode enabled, the image wasn't correctly added. 9 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐