Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/core/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
DocumentActionEventType,
FormatError,
info,
objectSize,
PermissionFlag,
shadow,
stringToUTF8String,
Expand Down Expand Up @@ -1111,7 +1110,7 @@ class Catalog {

get openAction() {
const obj = this.#catDict.get("OpenAction");
const openAction = Object.create(null);
const openAction = new Map();

if (obj instanceof Dict) {
// Convert the OpenAction dictionary into a format that works with
Expand All @@ -1123,18 +1122,14 @@ class Catalog {
Catalog.parseDestDictionary({ destDict, resultObj });

if (Array.isArray(resultObj.dest)) {
openAction.dest = resultObj.dest;
openAction.set("dest", resultObj.dest);
} else if (resultObj.action) {
openAction.action = resultObj.action;
openAction.set("action", resultObj.action);
}
} else if (isValidExplicitDest(obj)) {
openAction.dest = obj;
openAction.set("dest", obj);
}
return shadow(
this,
"openAction",
objectSize(openAction) > 0 ? openAction : null
);
return shadow(this, "openAction", openAction.size ? openAction : null);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -829,9 +829,9 @@ class PDFDocumentProxy {
}

/**
* @returns {Promise<any | null>} A promise that is resolved with an {Array}
* containing the destination, or `null` when no open action is present
* in the PDF.
* @returns {Promise<Map | null>} A promise that is resolved with a {Map}
* containing a destination or action, or `null` when no open action is
* present in the PDF.
*/
getOpenAction() {
return this._transport.getOpenAction();
Expand Down
14 changes: 5 additions & 9 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1774,11 +1774,9 @@ describe("api", function () {

it("gets non-default open action (with destination)", async function () {
const openAction = await pdfDocument.getOpenAction();
expect(openAction.dest).toEqual([
{ num: 15, gen: 0 },
{ name: "FitH" },
null,
]);
expect(openAction).toEqual(
new Map([["dest", [{ num: 15, gen: 0 }, { name: "FitH" }, null]]])
);
expect(openAction.action).toBeUndefined();
});

Expand All @@ -1796,16 +1794,14 @@ describe("api", function () {
const promise1 = loadingTask1.promise
.then(pdfDoc => pdfDoc.getOpenAction())
.then(function (openAction) {
expect(openAction.dest).toBeUndefined();
expect(openAction.action).toEqual("Print");
expect(openAction).toEqual(new Map([["action", "Print"]]));

return loadingTask1.destroy();
});
const promise2 = loadingTask2.promise
.then(pdfDoc => pdfDoc.getOpenAction())
.then(function (openAction) {
expect(openAction.dest).toBeUndefined();
expect(openAction.action).toEqual("Print");
expect(openAction).toEqual(new Map([["action", "Print"]]));

return loadingTask2.destroy();
});
Expand Down
4 changes: 2 additions & 2 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ const PDFViewerApplication = {
this._initializePdfHistory({
fingerprint: pdfDocument.fingerprints[0],
viewOnLoad,
initialDest: openAction?.dest,
initialDest: openAction?.get("dest"),
});
const initialBookmark = this.initialBookmark;

Expand Down Expand Up @@ -1788,7 +1788,7 @@ const PDFViewerApplication = {
if (pdfDocument !== this.pdfDocument) {
return; // The document was closed while the auto print data resolved.
}
let triggerAutoPrint = openAction?.action === "Print";
let triggerAutoPrint = openAction?.get("action") === "Print";

if (jsActions) {
console.warn("Warning: JavaScript support is not enabled");
Expand Down