diff --git a/src/core/obj.js b/src/core/obj.js index 7a875a216..700a4ca35 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -392,6 +392,28 @@ class Catalog { return shadow(this, 'pageMode', pageMode); } + get openActionDestination() { + const obj = this.catDict.get('OpenAction'); + let openActionDest = null; + + if (isDict(obj)) { + // Convert the OpenAction dictionary into a format that works with + // `parseDestDictionary`, to avoid having to re-implement those checks. + const destDict = new Dict(this.xref); + destDict.set('A', obj); + + const resultObj = { url: null, dest: null, }; + Catalog.parseDestDictionary({ destDict, resultObj, }); + + if (Array.isArray(resultObj.dest)) { + openActionDest = resultObj.dest; + } + } else if (Array.isArray(obj)) { + openActionDest = obj; + } + return shadow(this, 'openActionDestination', openActionDest); + } + get attachments() { const obj = this.catDict.get('Names'); let attachments = null; diff --git a/src/core/worker.js b/src/core/worker.js index 1d525d0da..df14cd3af 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -531,6 +531,10 @@ var WorkerMessageHandler = { return pdfManager.ensureCatalog('pageMode'); }); + handler.on('getOpenActionDestination', function(data) { + return pdfManager.ensureCatalog('openActionDestination'); + }); + handler.on('GetAttachments', function wphSetupGetAttachments(data) { return pdfManager.ensureCatalog('attachments'); diff --git a/src/display/api.js b/src/display/api.js index 6a75d8288..c89930ff1 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -650,6 +650,14 @@ class PDFDocumentProxy { return this._transport.getPageMode(); } + /** + * @return {Promise} A promise that is resolved with an {Array} containing the + * destination, or `null` when no open action is present in the PDF file. + */ + getOpenActionDestination() { + return this._transport.getOpenActionDestination(); + } + /** * @return {Promise} A promise that is resolved with a lookup table for * mapping named attachments to their content. @@ -2152,6 +2160,11 @@ class WorkerTransport { return this.messageHandler.sendWithPromise('GetPageMode', null); } + getOpenActionDestination() { + return this.messageHandler.sendWithPromise('getOpenActionDestination', + null); + } + getAttachments() { return this.messageHandler.sendWithPromise('GetAttachments', null); } diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 4ae03fbf0..021a361f9 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -650,6 +650,24 @@ describe('api', function() { }).catch(done.fail); }); + it('gets default open action destination', function(done) { + var loadingTask = getDocument(buildGetDocumentParams('tracemonkey.pdf')); + + loadingTask.promise.then(function(pdfDocument) { + return pdfDocument.getOpenActionDestination(); + }).then(function(dest) { + expect(dest).toEqual(null); + + loadingTask.destroy().then(done); + }).catch(done.fail); + }); + it('gets non-default open action destination', function(done) { + doc.getOpenActionDestination().then(function(dest) { + expect(dest).toEqual([{ num: 15, gen: 0, }, { name: 'FitH', }, null]); + done(); + }).catch(done.fail); + }); + it('gets non-existent attachments', function(done) { var promise = doc.getAttachments(); promise.then(function (data) {