12

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

Community
  • 1
  • 1
Mukesh Gupta
  • 1,373
  • 3
  • 17
  • 42
  • 1
    Yes, it's locked down for demo viewer. People who wants take a risk of content spoofing can remove this protection, in this case customized viewer will be able to displays unrelated/prank/offensive content under the viewer's domain name. – async5 May 23 '16 at 21:35
  • 1
    See also http://stackoverflow.com/questions/37364662/pdf-js-message-file-origin-does-not-match-viewers-amazon-s3 – async5 May 23 '16 at 21:38

5 Answers5

22

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

Mukesh Gupta
  • 1,373
  • 3
  • 17
  • 42
7

Add your domain/origin to HOSTED_VIEWER_ORIGINS array

SANTHOSH.SJ
  • 343
  • 1
  • 4
  • 7
0

I resolved this issue by adding this line in viewer.js

    var LOCAL_AUTO_DETECT_ORIGIN = window.location.origin;

  var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io'];

  HOSTED_VIEWER_ORIGINS.push(LOCAL_AUTO_DETECT_ORIGIN);
Pushparaj
  • 1,072
  • 8
  • 29
0

The problem in my case was the link wasnt in https while the site is secured

ChiiiN
  • 31
  • 1
0

pdfjs respect CORS settings. Do the following

  1. Go to viewer.js file and find the location of HOSTED_VIEWER_ORIGINS. Below that line add your domain to the array HOSTED_VIEWER_ORIGINS like this
    const LOCAL_AUTO_DETECT_ORIGIN = window.location.origin;
    HOSTED_VIEWER_ORIGINS.push(LOCAL_AUTO_DETECT_ORIGIN);
  1. if your file is hosted n AWS S3 bucket, then set CORS policy on the bucket to allow all your domains read files from that bucket

That should solve your prblem