Merge pull request #1926 from yurydelendik/fix-relative-url
Allow relative URLs in getDocument
This commit is contained in:
commit
09acd7b2b2
12
src/api.js
12
src/api.js
@ -32,11 +32,21 @@ PDFJS.getDocument = function getDocument(source) {
|
||||
if (!source.url && !source.data)
|
||||
error('Invalid parameter array, need either .data or .url');
|
||||
|
||||
// copy/use all keys as is except 'url' -- full path is required
|
||||
var params = {};
|
||||
for (var key in source) {
|
||||
if (key === 'url' && typeof window !== 'undefined') {
|
||||
params[key] = combineUrl(window.location.href, source[key]);
|
||||
continue;
|
||||
}
|
||||
params[key] = source[key];
|
||||
}
|
||||
|
||||
workerInitializedPromise = new PDFJS.Promise();
|
||||
workerReadyPromise = new PDFJS.Promise();
|
||||
transport = new WorkerTransport(workerInitializedPromise, workerReadyPromise);
|
||||
workerInitializedPromise.then(function transportInitialized() {
|
||||
transport.fetchDocument(source);
|
||||
transport.fetchDocument(params);
|
||||
});
|
||||
return workerReadyPromise;
|
||||
};
|
||||
|
@ -78,7 +78,6 @@ function combineUrl(baseUrl, url) {
|
||||
return baseUrl.substring(0, prefixLength + 1) + url;
|
||||
}
|
||||
}
|
||||
PDFJS.combineUrl = combineUrl;
|
||||
|
||||
// In a well-formed PDF, |cond| holds. If it doesn't, subsequent
|
||||
// behavior is undefined.
|
||||
|
@ -395,7 +395,7 @@ var PDFView = {
|
||||
if (typeof url === 'string') { // URL
|
||||
this.url = url;
|
||||
document.title = decodeURIComponent(getFileName(url)) || url;
|
||||
parameters.url = PDFJS.combineUrl(window.location.href, url);
|
||||
parameters.url = url;
|
||||
} else if (url && 'byteLength' in url) { // ArrayBuffer
|
||||
parameters.data = url;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user