mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02:00
[api-minor] Move the page reference/number caching into the API
Rather than having to handle this *manually* throughout the viewer, this functionality can instead be moved into the API which simplifies the code slightly.
This commit is contained in:
parent
fa69d9a3bc
commit
f6cd03955b
6 changed files with 42 additions and 74 deletions
|
@ -325,21 +325,10 @@ class PDFOutlineViewer extends BaseTreeViewer {
|
|||
if (Array.isArray(explicitDest)) {
|
||||
const [destRef] = explicitDest;
|
||||
|
||||
if (typeof destRef === "object" && destRef !== null) {
|
||||
pageNumber = this.linkService._cachedPageNumber(destRef);
|
||||
|
||||
if (!pageNumber) {
|
||||
try {
|
||||
pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
|
||||
|
||||
if (pdfDocument !== this._pdfDocument) {
|
||||
return null; // The document was closed while the data resolved.
|
||||
}
|
||||
this.linkService.cachePageRef(pageNumber, destRef);
|
||||
} catch {
|
||||
// Invalid page reference, ignore it and continue parsing.
|
||||
}
|
||||
}
|
||||
if (destRef && typeof destRef === "object") {
|
||||
// The page reference must be available, since the current method
|
||||
// won't be invoked until all pages have been loaded.
|
||||
pageNumber = pdfDocument.cachedPageNumber(destRef);
|
||||
} else if (Number.isInteger(destRef)) {
|
||||
pageNumber = destRef + 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue