Search code examples
javascriptmozillapdf.jsreader

Load pdf on foreign url with pdf.js


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).


Solution

  • 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