Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -754,6 +754,23 @@ class StructTreePage {

const element = new StructElementNode(this, dict);
map.set(dict, element);
switch (element.role) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test to make sure that this behavior can't regress in the future.

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.
8 changes: 7 additions & 1 deletion test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,12 @@
"lastPage": 1,
"type": "eq"
},
{ "id": "issue20324",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this file are useless.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was created running the add_test script so I thought it was needed somewhere. I'll revert it!

"file": "pdfs/issue20324.pdf",
"md5": "13250232aa91444f983279581d9c02d6",
"rounds": 1,
"type": "eq"
},
{
"id": "issue13561_reduced",
"file": "pdfs/issue13561_reduced.pdf",
Expand Down Expand Up @@ -13026,6 +13032,6 @@
"file": "pdfs/issue20232.pdf",
"md5": "cc53e96a8fd9eafbfbb74de564f37047",
"rounds": 1,
"type": "eq"
"type": "other"
}
]
35 changes: 35 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5043,6 +5043,41 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
canvasFactory.destroy(canvasAndCtx);
await loadingTask.destroy();
});

it("should collect all list and table items in StructTree", async function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any specific reason to have this test in this file instead of struct_tree_spec ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I'll move it

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();
});
});

describe("Multiple `getDocument` instances", function () {
Expand Down