Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Cross-Domain file ? #522

Closed
infantiablue opened this issue Sep 24, 2011 · 12 comments

Comments

@infantiablue
Copy link

commented Sep 24, 2011

Hi there,

Thank you for creating such an interesting open-source library. I am wondering if this support to call file cross domain. Such as, in the web view example, I set the kDefaultURL = http://domainB.com/file.pdf then I call that viewer.js from domainA.com and it didn't work.

Is there anyway to solve this issue ?

Thank you very much

@brendandahl

This comment has been minimized.

Copy link
Contributor

commented Sep 25, 2011

Hello,

The PDF file is requested through a XMLHttpRequest so all the usual cross site scripting rules apply. There are a number of ways to get around this such as a proxy running on domainA see http://en.wikipedia.org/wiki/XMLHttpRequest#Cross-domain_requests for more options.

Brendan

@joneschrisg

This comment has been minimized.

Copy link
Contributor

commented Sep 27, 2011

Also, if the server at domainB sets the HTTP CORS headers properly (https://developer.mozilla.org/en/http_access_control#Access-Control-Allow-Origin) then the cross-origin request will work in modern browsers.

@infantiablue

This comment has been minimized.

Copy link
Author

commented Sep 28, 2011

Thank you very much for your explanations. I tried to set up and it works for the simple example, which use the ajax method

var ajaxGet = function(url, callback){
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.mozResponseType = xhr.responseType = 'arraybuffer';
xhr.expected = (document.URL.indexOf('file:') === 0) ? 0 : 200;
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === xhr.expected) {
var data = (xhr.mozResponseArrayBuffer || xhr.mozResponse ||
xhr.responseArrayBuffer || xhr.response);

  callback(data);
}

};
xhr.send(null);
}

However, in the advanced sample (like the web demo), it still didn't work. I think that the problem came from the function to call the file, it didn't support the binary type buffer. Could you guys to show me more ? I am no very good at javascript.

Thank you again

@brendandahl

This comment has been minimized.

Copy link
Contributor

commented Nov 2, 2011

@infantiablue were you able to figure it out?

@firespeier

This comment has been minimized.

Copy link

commented Dec 1, 2011

How does the google doc viewer work around this problem?...probably a stupid question..

@brendandahl

This comment has been minimized.

Copy link
Contributor

commented Dec 1, 2011

I'm not exactly sure but their doc viewer uses lots of server side processing so they don't have the same restrictions as a browser only program.

@firespeier

This comment has been minimized.

Copy link

commented Dec 6, 2011

Does anybody know if there is a way to use the client's connection. E.g. download the file to a temp directory (with any kind of script) and then load it with pdf.js? I guess thats not possible because of security issues, he? Would it be possible with a certificate or so?

@shinedezign

This comment has been minimized.

Copy link

commented Aug 17, 2012

Hi

I have the same issue ! I am uploading the pdf from one domain and displaying it in another domain. I am getting this error message

PDF.JS Build: undefined
Message: Unexpected server response of 0.

How to solve this cross domian issue ?

I tried to add to a server's HTTP response headers but does not work. Any help !! :(

@gigaherz

This comment has been minimized.

Copy link
Contributor

commented Aug 17, 2012

You need to allow Cross-origin Requests in the PDF hosting domain, so that it allows requests from the viewer domain.

If you can't do that, then you can't do Cross-origin requests, because of security concerns.

@taxilian

This comment has been minimized.

Copy link

commented Aug 7, 2014

Here is how I solved this issue without changing pdf.js: http://colonelpanic.net/2014/08/using-pdf-js-web-worker-cross-domain-cors/

@fabi0w

This comment has been minimized.

Copy link

commented Apr 25, 2015

XMLHttpRequest cannot load http://www.cesp.com/my.pdf. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

???

@superlc0413

This comment has been minimized.

Copy link

commented Jan 11, 2017

I have a list of PDF filenames, I want to load the corresponding PDF when clicking one of them.How can i do this with PDFJS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.