From df5a4fd0a7db4a22a987427240af577ec5446165 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 2 May 2022 09:46:44 +0200 Subject: [PATCH] Support encoded dest-strings in /GoTo destination dictionaries (issue 14864) Interestingly enough this appears to be the very first case of *encoded* dest-strings, in /GoTo destination dictionaries, that we've actually come across. What's really fascinating is that it's less than a week after issue 14847, given that these issues are *somewhat* similar. --- src/core/catalog.js | 4 +++- test/pdfs/issue14864.pdf.link | 1 + test/test_manifest.json | 7 +++++++ test/unit/api_spec.js | 27 +++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 test/pdfs/issue14864.pdf.link diff --git a/src/core/catalog.js b/src/core/catalog.js index 0e8247d9b..c319b98fd 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -1576,7 +1576,9 @@ class Catalog { if (dest instanceof Name) { dest = dest.name; } - if (typeof dest === "string" || Array.isArray(dest)) { + if (typeof dest === "string") { + resultObj.dest = stringToPDFString(dest); + } else if (Array.isArray(dest)) { resultObj.dest = dest; } } diff --git a/test/pdfs/issue14864.pdf.link b/test/pdfs/issue14864.pdf.link new file mode 100644 index 000000000..e595c58c0 --- /dev/null +++ b/test/pdfs/issue14864.pdf.link @@ -0,0 +1 @@ +https://github.com/mozilla/pdf.js/files/8599802/songbook.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 540776747..10de596d1 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -6,6 +6,13 @@ "link": true, "type": "other" }, + { "id": "issue14864", + "file": "pdfs/issue14864.pdf", + "md5": "cfe5e68267d1e84ec909a915911974cf", + "rounds": 1, + "link": true, + "type": "other" + }, { "id": "filled-background-range", "file": "pdfs/filled-background.pdf", "md5": "2e3120255d9c3e79b96d2543b12d2589", diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 4cf8c7610..e0127e89f 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -1454,6 +1454,33 @@ describe("api", function () { await loadingTask.destroy(); }); + it("gets outline, with dest-strings using PDFDocEncoding (issue 14864)", async function () { + if (isNodeJS) { + pending("Linked test-cases are not supported in Node.js."); + } + const loadingTask = getDocument(buildGetDocumentParams("issue14864.pdf")); + const pdfDoc = await loadingTask.promise; + const outline = await pdfDoc.getOutline(); + + expect(Array.isArray(outline)).toEqual(true); + expect(outline.length).toEqual(6); + + expect(outline[4]).toEqual({ + dest: "Händel -- Halle🎆lujah", + url: null, + unsafeUrl: undefined, + newWindow: undefined, + title: "Händel -- Halle🎆lujah", + color: new Uint8ClampedArray([0, 0, 0]), + count: undefined, + bold: false, + italic: false, + items: [], + }); + + await loadingTask.destroy(); + }); + it("gets outline with non-displayable chars", async function () { const loadingTask = getDocument(buildGetDocumentParams("issue14267.pdf")); const pdfDoc = await loadingTask.promise;