Load pdf on foreign url with pdf.js

橙三吉。 提交于 2019-12-06 00:14:28

问题


I am trying to load pdf from another server to the viewer of pdf.js in my server.I got error "PDF.js v1.4.20 (build: b15f335) Message: file origin does not match viewer's"

I already checked many answer, many of them said that pass the pdf url through a proxy like:- link

After searching a lot i found that they release a new patch in which they have lock down any CDR request, correct me if i am wrong:-Here is the link

but in their user manual they specified that it is possible here is the link

I tried all method but not able to enable CDR on my server and many methods didn't work.

Please help me to resolve this issue. My Basic idea is to show pdf(which is hosted on 3rd party server) on my pdf reader(that i made it from pdf.js).


回答1:


I resolved this issue by comment this lines in viewer.js

if (fileOrigin !== viewerOrigin) {
throw new Error('file origin does not match viewer\'s');
}

and use proxy like this. http://192.168.0.101/web/viewer.html?file=https://cors-anywhere.herokuapp.com/pathofpdf.pdf




回答2:


Add your domain/origin to HOSTED_VIEWER_ORIGINS array



来源:https://stackoverflow.com/questions/37378251/load-pdf-on-foreign-url-with-pdf-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!