pdf.js插件使用跨域问题

2,926 阅读1分钟

问题: 使用pdf.js跨域

viewer.html?file=http://www.chuanbaofund.com/关于《川宝车厘子自由一号私募证券投资基金》成立的公告.pdf:1 Access to fetch at 'xx/xx.pdf' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

方案: 注释掉pdf.js里的1846-1848行,先使自己的项目能跨域

  • 步骤一: 注释掉pdf.js里的1846-1848行,先使自己的项目能跨域

  • 步骤二 服务器设置http:响应头

    但是放到服务器又发现一个问题,pdf.js功能都变成英文了, 所以需要配置以下