From e045cd4520da512b53bb94e6d7376d7566cc9387 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 29 Nov 2021 22:25:31 +0100 Subject: [PATCH 1/2] Remove the unused `skipCount` parameter from `Catalog.getPageDict` (PR 14311 follow-up) This was added in PR 14311, but given that I completely missed to update the `PDFDocument.getPage` signature accordingly it's completely unused. Given that things work just as fine as-is, let's simply remove that optional parameter for now; sorry about the churn here! --- src/core/catalog.js | 4 ++-- src/core/document.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/catalog.js b/src/core/catalog.js index a5355ad57..9a19e45e9 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -1085,7 +1085,7 @@ class Catalog { }); } - getPageDict(pageIndex, skipCount = false) { + getPageDict(pageIndex) { const capability = createPromiseCapability(); const nodesToVisit = [this._catDict.getRaw("Pages")]; const visitedNodes = new RefSet(); @@ -1153,7 +1153,7 @@ class Catalog { throw ex; } } - if (Number.isInteger(count) && count >= 0 && !skipCount) { + if (Number.isInteger(count) && count >= 0) { // Cache the Kids count, since it can reduce redundant lookups in // documents where all nodes are found at *one* level of the tree. const objId = currentNode.objId; diff --git a/src/core/document.js b/src/core/document.js index bc33b1952..21607253a 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -1388,7 +1388,7 @@ class PDFDocument { let pageIndex = 1; // The first page was already loaded. while (true) { try { - await this.getPage(pageIndex, /* skipCount = */ true); + await this.getPage(pageIndex); } catch (reasonLoop) { if (reasonLoop instanceof PageDictMissingException) { break; From 8ea740c8001739cb19ad23788734b276fe644fdb Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 29 Nov 2021 22:33:48 +0100 Subject: [PATCH 2/2] Slightly extend the "creates pdf doc from PDF file with bad XRef table" unit-test (PR 14304 follow-up) Given that we're able to "render" this document, let's extend the unit-test to actually check that we're able to obtain the operatorList; although given the overall issues in the document it'll be empty. --- test/unit/api_spec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 33226b46a..90df5b5d3 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -457,6 +457,14 @@ describe("api", function () { const pdfDocument = await loadingTask.promise; expect(pdfDocument.numPages).toEqual(1); + const page = await pdfDocument.getPage(1); + expect(page instanceof PDFPageProxy).toEqual(true); + + const opList = await page.getOperatorList(); + expect(opList.fnArray.length).toEqual(0); + expect(opList.argsArray.length).toEqual(0); + expect(opList.lastChunk).toEqual(true); + await loadingTask.destroy(); });