mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
[api-minor] Add support for relative URLs, in both annotations and the outline, by adding a docBaseUrl
parameter to PDFJS.getDocument
(bug 766086)
Note that in `FIREFOX/MOZCENTRAL/CHROME` builds of the standard viewer the `docBaseUrl` parameter will be set by default, since in that case it makes sense to use the current URL as a base. For the `GENERIC` viewer, or the API itself, it doesn't make sense to try and set the `docBaseUrl` by default. However, custom deployments/implementations may still find the parameter useful.
This commit is contained in:
parent
71a781ee5c
commit
d284cfd5eb
11 changed files with 304 additions and 47 deletions
|
@ -31,6 +31,9 @@
|
|||
}(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
|
||||
coreDocument) {
|
||||
|
||||
var warn = sharedUtil.warn;
|
||||
var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
|
||||
var shadow = sharedUtil.shadow;
|
||||
var NotImplementedException = sharedUtil.NotImplementedException;
|
||||
var MissingDataException = sharedUtil.MissingDataException;
|
||||
var createPromiseCapability = sharedUtil.createPromiseCapability;
|
||||
|
@ -49,6 +52,19 @@ var BasePdfManager = (function BasePdfManagerClosure() {
|
|||
return this._docId;
|
||||
},
|
||||
|
||||
get docBaseUrl() {
|
||||
var docBaseUrl = null;
|
||||
if (this._docBaseUrl) {
|
||||
var absoluteUrl = createValidAbsoluteUrl(this._docBaseUrl);
|
||||
if (absoluteUrl) {
|
||||
docBaseUrl = absoluteUrl.href;
|
||||
} else {
|
||||
warn('Invalid absolute docBaseUrl: "' + this._docBaseUrl + '".');
|
||||
}
|
||||
}
|
||||
return shadow(this, 'docBaseUrl', docBaseUrl);
|
||||
},
|
||||
|
||||
onLoadedStream: function BasePdfManager_onLoadedStream() {
|
||||
throw new NotImplementedException();
|
||||
},
|
||||
|
@ -110,8 +126,10 @@ var BasePdfManager = (function BasePdfManagerClosure() {
|
|||
})();
|
||||
|
||||
var LocalPdfManager = (function LocalPdfManagerClosure() {
|
||||
function LocalPdfManager(docId, data, password, evaluatorOptions) {
|
||||
function LocalPdfManager(docId, data, password, evaluatorOptions,
|
||||
docBaseUrl) {
|
||||
this._docId = docId;
|
||||
this._docBaseUrl = docBaseUrl;
|
||||
this.evaluatorOptions = evaluatorOptions;
|
||||
var stream = new Stream(data);
|
||||
this.pdfDocument = new PDFDocument(this, stream, password);
|
||||
|
@ -158,8 +176,10 @@ var LocalPdfManager = (function LocalPdfManagerClosure() {
|
|||
})();
|
||||
|
||||
var NetworkPdfManager = (function NetworkPdfManagerClosure() {
|
||||
function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions) {
|
||||
function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions,
|
||||
docBaseUrl) {
|
||||
this._docId = docId;
|
||||
this._docBaseUrl = docBaseUrl;
|
||||
this.msgHandler = args.msgHandler;
|
||||
this.evaluatorOptions = evaluatorOptions;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue