mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58: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
|
@ -157,6 +157,7 @@ var Catalog = (function CatalogClosure() {
|
|||
Catalog.parseDestDictionary({
|
||||
destDict: outlineDict,
|
||||
resultObj: data,
|
||||
docBaseUrl: this.pdfManager.docBaseUrl,
|
||||
});
|
||||
var title = outlineDict.get('Title');
|
||||
var flags = outlineDict.get('F') || 0;
|
||||
|
@ -590,6 +591,8 @@ var Catalog = (function CatalogClosure() {
|
|||
* @param {Dict} destDict - The dictionary containing the destination.
|
||||
* @param {Object} resultObj - The object where the parsed destination
|
||||
* properties will be placed.
|
||||
* @param {string} docBaseUrl - (optional) The document base URL that is used
|
||||
* when attempting to recover valid absolute URLs from relative ones.
|
||||
*/
|
||||
Catalog.parseDestDictionary = function Catalog_parseDestDictionary(params) {
|
||||
// Lets URLs beginning with 'www.' default to using the 'http://' protocol.
|
||||
|
@ -619,6 +622,7 @@ var Catalog = (function CatalogClosure() {
|
|||
warn('Catalog_parseDestDictionary: "resultObj" must be an object.');
|
||||
return;
|
||||
}
|
||||
var docBaseUrl = params.docBaseUrl || null;
|
||||
|
||||
var action = destDict.get('A'), url, dest;
|
||||
if (isDict(action)) {
|
||||
|
@ -694,7 +698,7 @@ var Catalog = (function CatalogClosure() {
|
|||
|
||||
if (isString(url)) {
|
||||
url = tryConvertUrlEncoding(url);
|
||||
var absoluteUrl = createValidAbsoluteUrl(url);
|
||||
var absoluteUrl = createValidAbsoluteUrl(url, docBaseUrl);
|
||||
if (absoluteUrl) {
|
||||
resultObj.url = absoluteUrl.href;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue