diff --git a/src/display/api.js b/src/display/api.js index 97c97f95f..1b637000e 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -2101,6 +2101,8 @@ class WorkerTransport { if (intentState.displayReadyCapability) { intentState.displayReadyCapability.reject(new Error(data.error)); + } else if (intentState.opListReadCapability) { + intentState.opListReadCapability.reject(new Error(data.error)); } else { throw new Error(data.error); } diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index de132ddba..10325b9f3 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -1236,6 +1236,7 @@ describe('api', function() { done(); }).catch(done.fail); }); + it('gets operatorList with JPEG image (issue 4888)', function(done) { let loadingTask = getDocument(buildGetDocumentParams('cmykjpeg.pdf')); @@ -1254,6 +1255,43 @@ describe('api', function() { }); }).catch(done.fail); }); + + it('gets operatorList, from corrupt PDF file (issue 8702), ' + + 'with/without `stopAtErrors` set', function(done) { + const loadingTask1 = getDocument(buildGetDocumentParams('issue8702.pdf', { + stopAtErrors: false, // The default value. + })); + const loadingTask2 = getDocument(buildGetDocumentParams('issue8702.pdf', { + stopAtErrors: true, + })); + + const result1 = loadingTask1.promise.then((pdfDoc) => { + return pdfDoc.getPage(1).then((pdfPage) => { + return pdfPage.getOperatorList().then((opList) => { + expect(opList.fnArray.length).toEqual(722); + expect(opList.argsArray.length).toEqual(722); + expect(opList.lastChunk).toEqual(true); + + return loadingTask1.destroy(); + }); + }); + }); + + const result2 = loadingTask2.promise.then((pdfDoc) => { + return pdfDoc.getPage(1).then((pdfPage) => { + return pdfPage.getOperatorList().then((opList) => { + expect(opList.fnArray.length).toEqual(0); + expect(opList.argsArray.length).toEqual(0); + expect(opList.lastChunk).toEqual(true); + + return loadingTask2.destroy(); + }); + }); + }); + + Promise.all([result1, result2]).then(done, done.fail); + }); + it('gets document stats after parsing page', function(done) { var promise = page.getOperatorList().then(function () { return pdfDocument.getStats();