Skip to content

Commit b15f335

Browse files
committed
Merge pull request #6930 from Snuffleupagus/page-labels-standard-numbering
[api-minor] Change `getPageLabels` to always return the pageLabels, even if they are identical to standard page numbering
2 parents 1f2910b + 1140a34 commit b15f335

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/core/obj.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,7 @@ var Catalog = (function CatalogClosure() {
343343
currentLabel = '';
344344
currentIndex++;
345345
}
346-
347-
// Ignore PageLabels if they correspond to standard page numbering.
348-
for (i = 0, ii = this.numPages; i < ii; i++) {
349-
if (pageLabels[i] !== (i + 1).toString()) {
350-
break;
351-
}
352-
}
353-
return (i === ii ? [] : pageLabels);
346+
return pageLabels;
354347
},
355348

356349
get attachments() {

src/display/api.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -691,11 +691,9 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
691691
return this.transport.getDestination(id);
692692
},
693693
/**
694-
* @return {Promise} A promise that is resolved with: an Array containing
695-
* the pageLabels that correspond to the pageIndexes; or null, when no
696-
* pageLabels are present in the PDF file.
697-
* NOTE: If the pageLabels are all identical to standard page numbering,
698-
* i.e. [1, 2, 3, ...], the promise is resolved with an empty Array.
694+
* @return {Promise} A promise that is resolved with:
695+
* an Array containing the pageLabels that correspond to the pageIndexes,
696+
* or `null` when no pageLabels are present in the PDF file.
699697
*/
700698
getPageLabels: function PDFDocumentProxy_getPageLabels() {
701699
return this.transport.getPageLabels();

test/unit/api_spec.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -338,25 +338,34 @@ describe('api', function() {
338338
it('gets page labels', function () {
339339
// PageLabels with Roman/Arabic numerals.
340340
var url0 = combineUrl(window.location.href, '../pdfs/bug793632.pdf');
341-
var promise0 = PDFJS.getDocument(url0).promise.then(function (pdfDoc) {
341+
var loadingTask0 = PDFJS.getDocument(url0);
342+
var promise0 = loadingTask0.promise.then(function (pdfDoc) {
342343
return pdfDoc.getPageLabels();
343344
});
345+
344346
// PageLabels with only a label prefix.
345347
var url1 = combineUrl(window.location.href, '../pdfs/issue1453.pdf');
346-
var promise1 = PDFJS.getDocument(url1).promise.then(function (pdfDoc) {
348+
var loadingTask1 = PDFJS.getDocument(url1);
349+
var promise1 = loadingTask1.promise.then(function (pdfDoc) {
347350
return pdfDoc.getPageLabels();
348351
});
352+
349353
// PageLabels identical to standard page numbering.
350354
var url2 = combineUrl(window.location.href, '../pdfs/rotation.pdf');
351-
var promise2 = PDFJS.getDocument(url2).promise.then(function (pdfDoc) {
355+
var loadingTask2 = PDFJS.getDocument(url2);
356+
var promise2 = loadingTask2.promise.then(function (pdfDoc) {
352357
return pdfDoc.getPageLabels();
353358
});
354359

355360
waitsForPromiseResolved(Promise.all([promise0, promise1, promise2]),
356361
function (pageLabels) {
357362
expect(pageLabels[0]).toEqual(['i', 'ii', 'iii', '1']);
358363
expect(pageLabels[1]).toEqual(['Front Page1']);
359-
expect(pageLabels[2]).toEqual([]);
364+
expect(pageLabels[2]).toEqual(['1', '2']);
365+
366+
loadingTask0.destroy();
367+
loadingTask1.destroy();
368+
loadingTask2.destroy();
360369
});
361370
});
362371
it('gets attachments', function() {

0 commit comments

Comments
 (0)