Merge pull request #14191 from Snuffleupagus/viewer-empty-pageLabels

Ignore pageLabels, in the viewer, when they're all empty
This commit is contained in:
Tim van der Meij 2021-10-27 20:01:45 +02:00 committed by GitHub
commit 6f3700b393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1632,18 +1632,21 @@ 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;
// 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;
}
}
let i = 0;
// Ignore page labels that correspond to standard page numbering.
while (i < numLabels && labels[i] === (i + 1).toString()) {
i++;
}
if (i === numLabels) {
if (standardLabels >= numLabels || emptyLabels >= numLabels) {
return;
}
const { pdfViewer, pdfThumbnailViewer, toolbar } = this;