PDF.js 版本: 2.0.0
服務(wù)器需要做一些支持
響應(yīng)頭中添加
'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'];