Skip to content

Commit

Permalink
Merge pull request #17847 from Snuffleupagus/issue-17846
Browse files Browse the repository at this point in the history
Add better support for /Launch actions with /FileSpec dictionaries (issue 17846)
  • Loading branch information
timvandermeij authored Mar 28, 2024
2 parents 236a4df + 0d03993 commit 55db439
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/core/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -1568,9 +1568,13 @@ class Catalog {
case "GoToR":
const urlDict = action.get("F");
if (urlDict instanceof Dict) {
// We assume that we found a FileSpec dictionary
// and fetch the URL without checking any further.
url = urlDict.get("F") || null;
const fs = new FileSpec(
urlDict,
/* xref = */ null,
/* skipContent = */ true
);
const { filename } = fs.serializable;
url = filename;
} else if (typeof urlDict === "string") {
url = urlDict;
}
Expand Down
16 changes: 10 additions & 6 deletions src/core/file_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ function pickPlatformItem(dict) {
* collections attributes and related files (/RF)
*/
class FileSpec {
constructor(root, xref) {
#contentAvailable = false;

constructor(root, xref, skipContent = false) {
if (!(root instanceof Dict)) {
return;
}
Expand All @@ -57,10 +59,12 @@ class FileSpec {
if (root.has("RF")) {
warn("Related file specifications are not supported");
}
this.contentAvailable = true;
if (!root.has("EF")) {
this.contentAvailable = false;
warn("Non-embedded file specifications are not supported");
if (!skipContent) {
if (root.has("EF")) {
this.#contentAvailable = true;
} else {
warn("Non-embedded file specifications are not supported");
}
}
}

Expand All @@ -76,7 +80,7 @@ class FileSpec {
}

get content() {
if (!this.contentAvailable) {
if (!this.#contentAvailable) {
return null;
}
if (!this.contentRef && this.root) {
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
!issue7507.pdf
!issue6931_reduced.pdf
!issue14847.pdf
!issue17846.pdf
!doc_actions.pdf
!issue7580.pdf
!issue7598.pdf
Expand Down
Binary file added test/pdfs/issue17846.pdf
Binary file not shown.
20 changes: 20 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2926,6 +2926,26 @@ describe("api", function () {
await loadingTask.destroy();
});

it("gets annotations containing /Launch action with /FileSpec dictionary (issue 17846)", async function () {
const loadingTask = getDocument(buildGetDocumentParams("issue17846.pdf"));
const pdfDoc = await loadingTask.promise;
const pdfPage = await pdfDoc.getPage(1);

const annotations = await pdfPage.getAnnotations();
expect(annotations.length).toEqual(1);

const { annotationType, url, unsafeUrl, newWindow } = annotations[0];
expect(annotationType).toEqual(AnnotationType.LINK);

expect(url).toBeUndefined();
expect(unsafeUrl).toEqual(
"对不起/没关系/1_1_模块1行政文件和药品信息目录.pdf"
);
expect(newWindow).toEqual(true);

await loadingTask.destroy();
});

it("gets text content", async function () {
const { items, styles } = await page.getTextContent();

Expand Down

0 comments on commit 55db439

Please sign in to comment.