1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-23 08:38:06 +02:00

Merge pull request #10334 from Snuffleupagus/OpenAction-dest

[api-minor] Add support for OpenAction destinations (issue 10332)
This commit is contained in:
Tim van der Meij 2018-12-23 20:49:50 +01:00 committed by GitHub
commit 103f4616ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 99 additions and 10 deletions

View file

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

View file

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

View file

@ -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.
@ -2167,6 +2175,11 @@ class WorkerTransport {
return this.messageHandler.sendWithPromise('GetPageMode', null);
}
getOpenActionDestination() {
return this.messageHandler.sendWithPromise('getOpenActionDestination',
null);
}
getAttachments() {
return this.messageHandler.sendWithPromise('GetAttachments', null);
}