-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Collect all child nodes of lists and tables in StructTree #20327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1676,6 +1676,12 @@ | |
| "lastPage": 1, | ||
| "type": "eq" | ||
| }, | ||
| { "id": "issue20324", | ||
|
||
| "file": "pdfs/issue20324.pdf", | ||
| "md5": "13250232aa91444f983279581d9c02d6", | ||
| "rounds": 1, | ||
| "type": "eq" | ||
| }, | ||
| { | ||
| "id": "issue13561_reduced", | ||
| "file": "pdfs/issue13561_reduced.pdf", | ||
|
|
@@ -13026,6 +13032,6 @@ | |
| "file": "pdfs/issue20232.pdf", | ||
| "md5": "cc53e96a8fd9eafbfbb74de564f37047", | ||
| "rounds": 1, | ||
| "type": "eq" | ||
| "type": "other" | ||
| } | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() { | ||
|
||
| 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 () { | ||
|
|
||
There was a problem hiding this comment.
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.