Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Viewer unable to display PDF files retrieved from different domains #6446

Closed
hammady opened this issue Sep 14, 2015 · 4 comments
Closed

Viewer unable to display PDF files retrieved from different domains #6446

hammady opened this issue Sep 14, 2015 · 4 comments

Comments

@hammady
Copy link

hammady commented Sep 14, 2015

I am unable to display a PDF retrieved via SSL. Look at the demo with an SSL link:

http://mozilla.github.io/pdf.js/web/viewer.html?file=https://d2fqdaa97sxcjl.cloudfront.net/fulltext/c6f10e90-5646-4161-a72b-fa78bf76c5a0/I901_payment_confirmation_07262015.PDF

Is this a limitation of PDF.js? The certificates are OK and I believe this is something not related to PDF.js, if the browser can get it, then PDF.js should.

@Rob--W
Copy link
Member

Rob--W commented Sep 14, 2015

This is not an issue with PDF.js, it's an intentional security feature of browsers that websites cannot directly read files from other websites.

Although it's possible to circumvent the issue using a proxy (e.g. as explained at #1000 (comment)), a better solution is to host PDF.js on the same website (e.g. cloudfront in your case). Then the URL would be something like: https://d2fqdaa97sxcjl.cloudfront.net/web/viewer.html?file=/fulltext/c6f10e90-5646-4161-a72b-fa78bf76c5a0/I901_payment_confirmation_07262015.PDF

See https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-xhr and https://github.com/mozilla/pdf.js/wiki/Setup-PDF.js-in-a-website.

@Rob--W Rob--W closed this as completed Sep 14, 2015
@hammady
Copy link
Author

hammady commented Sep 14, 2015

Thanks for pointing out the CORS issue. The cloud front endpoint was not configured for CORS (now configured), but the S3 origin behind it was. However, if you inspect the network requests while loading the above link, it shows 200 OK for the PDF resource which means the file was pulled correctly. I have tried HTTP and HTTPS with no luck (200 OK though in both cases). Any clue how this can be debugged?
I can't host the viewer on cloudfront because it is part of a bigger web app which has its own authentication to load the viewer page. @Rob--W

@Rob--W
Copy link
Member

Rob--W commented Sep 14, 2015

@hammady HTTP 200 OK means that the server found the resource. After that, what matters is that the Access-Control-Allow-Origin header is set.

If it still does not work, please include a log / screenshot of the network traffic.

@hammady
Copy link
Author

hammady commented Sep 15, 2015

@Rob--W it is working now, I guess there was a big latency in applying CORS rules in AWS. Thanks!

@hammady hammady changed the title Viewer unable to display PDF files retrieved through SSL Viewer unable to display PDF files retrieved from different domains Sep 15, 2015
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants