From c85cd80b1bb8465feac8956ff57c96e92785ff55 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 25 Oct 2021 13:25:34 +0200 Subject: [PATCH 1/2] Remove unnecessary pageLabel length-check in the viewer Given how the pageLabel array is defined, see https://github.com/mozilla/pdf.js/blob/1ab9a6e36e84389775e5f3d6faebdb6b327b8d62/src/core/catalog.js#L627, it shouldn't be necessary to check the length in the viewer. --- web/app.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/web/app.js b/web/app.js index bde59a9d2..68c4053e1 100644 --- a/web/app.js +++ b/web/app.js @@ -1632,12 +1632,6 @@ const PDFViewerApplication = { return; } const numLabels = labels.length; - if (numLabels !== this.pagesCount) { - console.error( - "The number of Page Labels does not match the number of pages in the document." - ); - return; - } let i = 0; // Ignore page labels that correspond to standard page numbering. while (i < numLabels && labels[i] === (i + 1).toString()) { From 66c26d70d4bb50fb233cd33ef5156767c36aff33 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 25 Oct 2021 13:43:19 +0200 Subject: [PATCH 2/2] Ignore pageLabels, in the viewer, when they're all empty Unfortunately there exist PDF documents where all pageLabels are empty strings, see e.g. http://www.cs.cornell.edu/~ragarwal/pubs/blk-switch.pdf (taken from an old issue), which result in the pageNumber-input being completely blank. That doesn't seem very helpful, and this patch simply extends the approach used to ignore pageLabels that are identical to standard page numbering. --- web/app.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/web/app.js b/web/app.js index 68c4053e1..c3743396e 100644 --- a/web/app.js +++ b/web/app.js @@ -1632,12 +1632,21 @@ const PDFViewerApplication = { return; } const numLabels = labels.length; - let i = 0; - // Ignore page labels that correspond to standard page numbering. - while (i < numLabels && labels[i] === (i + 1).toString()) { - i++; + // Ignore page labels that correspond to standard page numbering, + // or page labels that are all empty. + let standardLabels = 0, + emptyLabels = 0; + for (let i = 0; i < numLabels; i++) { + const label = labels[i]; + if (label === (i + 1).toString()) { + standardLabels++; + } else if (label === "") { + emptyLabels++; + } else { + break; + } } - if (i === numLabels) { + if (standardLabels >= numLabels || emptyLabels >= numLabels) { return; } const { pdfViewer, pdfThumbnailViewer, toolbar } = this;