From 136c1faa7f168747a4771a673336fbbc4d95e5c4 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Fri, 29 Mar 2024 20:58:24 +0100 Subject: [PATCH] Display outlines even if one has no title Fixes #17856. --- src/core/catalog.js | 4 ++-- test/pdfs/issue17856.pdf.link | 2 ++ test/test_manifest.json | 8 ++++++++ test/unit/api_spec.js | 30 ++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 test/pdfs/issue17856.pdf.link diff --git a/src/core/catalog.js b/src/core/catalog.js index 55d0e13c5..29eb7944f 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -324,7 +324,7 @@ class Catalog { continue; } if (!outlineDict.has("Title")) { - throw new FormatError("Invalid outline item encountered."); + warn("Invalid outline item encountered."); } const data = { url: null, dest: null, action: null }; @@ -357,7 +357,7 @@ class Catalog { unsafeUrl: data.unsafeUrl, newWindow: data.newWindow, setOCGState: data.setOCGState, - title: stringToPDFString(title), + title: typeof title === "string" ? stringToPDFString(title) : "", color: rgbColor, count: Number.isInteger(count) ? count : undefined, bold: !!(flags & 2), diff --git a/test/pdfs/issue17856.pdf.link b/test/pdfs/issue17856.pdf.link new file mode 100644 index 000000000..cd729656d --- /dev/null +++ b/test/pdfs/issue17856.pdf.link @@ -0,0 +1,2 @@ +https://github.com/mozilla/pdf.js/files/14808044/outline-without-title.pdf + diff --git a/test/test_manifest.json b/test/test_manifest.json index 3fd5ba0c5..767c8d4a1 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -9779,5 +9779,13 @@ "rounds": 1, "link": true, "type": "eq" + }, + { + "id": "issue17856", + "file": "pdfs/issue17856.pdf", + "md5": "b31e5258948f0f4bb99eb5d4127c2162", + "rounds": 1, + "link": true, + "type": "other" } ] diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index d9cbdfa46..020201b00 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -1719,6 +1719,36 @@ describe("api", function () { await loadingTask.destroy(); }); + it("gets outline, with missing title (issue 17856)", async function () { + if (isNodeJS) { + pending("Linked test-cases are not supported in Node.js."); + } + const loadingTask = getDocument(buildGetDocumentParams("issue17856.pdf")); + const pdfDoc = await loadingTask.promise; + const outline = await pdfDoc.getOutline(); + + expect(Array.isArray(outline)).toEqual(true); + expect(outline.length).toEqual(9); + + expect(outline[0]).toEqual({ + action: null, + attachment: undefined, + dest: "section.1", + url: null, + unsafeUrl: undefined, + newWindow: undefined, + setOCGState: undefined, + title: "", + color: new Uint8ClampedArray([0, 0, 0]), + count: undefined, + bold: false, + italic: false, + items: [], + }); + + 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.");