|
|
@ -80,71 +80,76 @@ var PDFLinkService = (function PDFLinkServiceClosure() { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param dest - The PDF destination object. |
|
|
|
* @param {string|Array} dest - The named, or explicit, PDF destination. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
navigateTo: function PDFLinkService_navigateTo(dest) { |
|
|
|
navigateTo(dest) { |
|
|
|
var destString = ''; |
|
|
|
let goToDestination = ({ namedDest, explicitDest, }) => { |
|
|
|
var self = this; |
|
|
|
// Dest array looks like that: <page-ref> </XYZ|/FitXXX> <args..>
|
|
|
|
|
|
|
|
let destRef = explicitDest[0], pageNumber; |
|
|
|
|
|
|
|
|
|
|
|
var goToDestination = function(destRef) { |
|
|
|
|
|
|
|
// dest array looks like that: <page-ref> </XYZ|/FitXXX> <args..>
|
|
|
|
|
|
|
|
var pageNumber; |
|
|
|
|
|
|
|
if (destRef instanceof Object) { |
|
|
|
if (destRef instanceof Object) { |
|
|
|
pageNumber = self._cachedPageNumber(destRef); |
|
|
|
pageNumber = this._cachedPageNumber(destRef); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pageNumber === null) { |
|
|
|
|
|
|
|
// Fetch the page reference if it's not yet available. This could
|
|
|
|
|
|
|
|
// only occur during loading, before all pages have been resolved.
|
|
|
|
|
|
|
|
this.pdfDocument.getPageIndex(destRef).then((pageIndex) => { |
|
|
|
|
|
|
|
this.cachePageRef(pageIndex + 1, destRef); |
|
|
|
|
|
|
|
goToDestination({ namedDest, explicitDest, }); |
|
|
|
|
|
|
|
}).catch(() => { |
|
|
|
|
|
|
|
console.error(`PDFLinkService.navigateTo: "${destRef}" is not ` + |
|
|
|
|
|
|
|
`a valid page reference, for dest="${dest}".`); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} else if ((destRef | 0) === destRef) { // Integer
|
|
|
|
} else if ((destRef | 0) === destRef) { // Integer
|
|
|
|
pageNumber = destRef + 1; |
|
|
|
pageNumber = destRef + 1; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
console.error('PDFLinkService_navigateTo: "' + destRef + |
|
|
|
console.error(`PDFLinkService.navigateTo: "${destRef}" is not ` + |
|
|
|
'" is not a valid destination reference.'); |
|
|
|
`a valid destination reference, for dest="${dest}".`); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) { |
|
|
|
if (pageNumber) { |
|
|
|
console.error(`PDFLinkService.navigateTo: "${pageNumber}" is not ` + |
|
|
|
if (pageNumber < 1 || pageNumber > self.pagesCount) { |
|
|
|
`a valid page number, for dest="${dest}".`); |
|
|
|
console.error('PDFLinkService_navigateTo: "' + pageNumber + |
|
|
|
|
|
|
|
'" is a non-existent page number.'); |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
self.pdfViewer.scrollPageIntoView({ |
|
|
|
|
|
|
|
|
|
|
|
this.pdfViewer.scrollPageIntoView({ |
|
|
|
pageNumber, |
|
|
|
pageNumber, |
|
|
|
destArray: dest, |
|
|
|
destArray: explicitDest, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (self.pdfHistory) { |
|
|
|
if (this.pdfHistory) { // Update the browsing history, if enabled.
|
|
|
|
// Update the browsing history.
|
|
|
|
this.pdfHistory.push({ |
|
|
|
self.pdfHistory.push({ |
|
|
|
dest: explicitDest, |
|
|
|
dest, |
|
|
|
hash: namedDest, |
|
|
|
hash: destString, |
|
|
|
page: pageNumber, |
|
|
|
page: pageNumber |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
self.pdfDocument.getPageIndex(destRef).then(function (pageIndex) { |
|
|
|
|
|
|
|
self.cachePageRef(pageIndex + 1, destRef); |
|
|
|
|
|
|
|
goToDestination(destRef); |
|
|
|
|
|
|
|
}).catch(function () { |
|
|
|
|
|
|
|
console.error('PDFLinkService_navigateTo: "' + destRef + |
|
|
|
|
|
|
|
'" is not a valid page reference.'); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var destinationPromise; |
|
|
|
new Promise((resolve, reject) => { |
|
|
|
if (typeof dest === 'string') { |
|
|
|
if (typeof dest === 'string') { |
|
|
|
destString = dest; |
|
|
|
this.pdfDocument.getDestination(dest).then((destArray) => { |
|
|
|
destinationPromise = this.pdfDocument.getDestination(dest); |
|
|
|
resolve({ |
|
|
|
} else { |
|
|
|
namedDest: dest, |
|
|
|
destinationPromise = Promise.resolve(dest); |
|
|
|
explicitDest: destArray, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
destinationPromise.then(function(destination) { |
|
|
|
resolve({ |
|
|
|
dest = destination; |
|
|
|
namedDest: '', |
|
|
|
if (!(destination instanceof Array)) { |
|
|
|
explicitDest: dest, |
|
|
|
console.error('PDFLinkService_navigateTo: "' + destination + |
|
|
|
}); |
|
|
|
'" is not a valid destination array.'); |
|
|
|
}).then((data) => { |
|
|
|
|
|
|
|
if (!(data.explicitDest instanceof Array)) { |
|
|
|
|
|
|
|
console.error(`PDFLinkService.navigateTo: "${data.explicitDest}" is` + |
|
|
|
|
|
|
|
` not a valid destination array, for dest="${dest}".`); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
goToDestination(destination[0]); |
|
|
|
goToDestination(data); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|