PDF.js 版本: 2.0.0
服务器需要做一些支持
响应头中添加
'Access-Control-Allow-Origin' '*'
例如我的 nginx 配置
server {
listen 80;
server_name 127.0.0.1;
location / {
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
root /home/*****/IdeaProjects/pdfjs-1.10.88-dist;
index index.html;
}
}
修改 PDF.js 代码,分两种情况
未编译,修改 app.js 中的这行代码
var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io'];
网友评论