Skip to content

Commit

Permalink
Display outlines even if one has no title
Browse files Browse the repository at this point in the history
Fixes #17856.
  • Loading branch information
calixteman committed Mar 29, 2024
1 parent 55db439 commit 136c1fa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions test/pdfs/issue17856.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
https://github.com/mozilla/pdf.js/files/14808044/outline-without-title.pdf

8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9779,5 +9779,13 @@
"rounds": 1,
"link": true,
"type": "eq"
},
{
"id": "issue17856",
"file": "pdfs/issue17856.pdf",
"md5": "b31e5258948f0f4bb99eb5d4127c2162",
"rounds": 1,
"link": true,
"type": "other"
}
]
30 changes: 30 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down

0 comments on commit 136c1fa

Please sign in to comment.