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.
This commit is contained in:
Jonas Jenwald 2021-10-25 13:43:19 +02:00
parent c85cd80b1b
commit 66c26d70d4

View File

@ -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;