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
17 changes: 17 additions & 0 deletions src/core/struct_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,23 @@ class StructTreePage {

const element = new StructElementNode(this, dict);
map.set(dict, element);
switch (element.role) {
case "L":
case "LBody":
case "LI":
case "Table":
case "THead":
case "TBody":
case "TFoot":
case "TR": {
// Always collect all child nodes of lists and tables, even empty ones
for (const kid of element.kids) {
if (kid.type === StructElementType.ELEMENT) {
this.addNode(kid.dict, map, level - 1);
}
}
}
}

const parent = dict.get("P");

Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@
!autoprint.pdf
!bug1811694.pdf
!bug1811510.pdf
!issue20324.pdf
!bug1815476.pdf
!issue16021.pdf
!bug1770750.pdf
Expand Down
Binary file added test/pdfs/issue20324.pdf
Binary file not shown.
28 changes: 28 additions & 0 deletions test/unit/struct_tree_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,34 @@ describe("struct tree", function () {
},
struct
);
});

it("should collect all list and table items in StructTree", async function () {
const findNodes = (node, check) => {
const results = [];
if (check(node)) {
results.push(node);
}
if (node.children) {
for (const child of node.children) {
results.push(...findNodes(child, check));
}
}
return results;
};
const loadingTask = getDocument(buildGetDocumentParams("issue20324.pdf"));

const pdfDoc = await loadingTask.promise;
const page = await pdfDoc.getPage(1);
const tree = await page.getStructTree({
includeMarkedContent: true,
});
const cells = findNodes(tree, node => node.role === "TD");
expect(cells.length).toEqual(4);

const listItems = findNodes(tree, node => node.role === "LI");
expect(listItems.length).toEqual(4);

await loadingTask.destroy();
});
});