Class StructureTreeMerger
- java.lang.Object
-
- com.pd4ml.pdf.merge.internal.StructureTreeMerger
-
public final class StructureTreeMerger extends java.lang.ObjectReconciles the accessibility structure tree (/StructTreeRoot/StructElem/ParentTree//StructParents) across the pages pulled in from one or more source documents, building a single merged tree in the target document.com.pd4ml.pdf.coshas no built-in awareness of this model (it's read-only plumbing); this class implements the relevant parts of the structure-tree chapter of the PDF spec directly.One instance is used for an entire merge operation, sharing the same
COSObjectImporterused for page content so aStructElem's/Pgback-reference and a page's own clone are always the same target object.Best-effort behavior: a page whose source document isn't tagged (or that itself has no
/StructParents) is simply included with no structure; the merged document ends up tagged only if at least one selected page contributed structure.
-
-
Constructor Summary
Constructors Constructor Description StructureTreeMerger(COSObjectImporter importer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description COSObjectfinish()Finalizes the merged tree: prunes any structure that ended up referencing pages that were never actually selected/cloned (e.g.voidmergePage(COSDocument sourceDoc, COSDictionary sourceStructTreeRoot, COSDictionary sourcePageDict, COSDictionary clonedPageDict)Merges one page's structure contribution, if any.
-
-
-
Constructor Detail
-
StructureTreeMerger
public StructureTreeMerger(COSObjectImporter importer)
-
-
Method Detail
-
mergePage
public void mergePage(COSDocument sourceDoc, COSDictionary sourceStructTreeRoot, COSDictionary sourcePageDict, COSDictionary clonedPageDict)
Merges one page's structure contribution, if any.sourceStructTreeRootisnullwhen the source document isn't tagged at all -- the page is then simply left untagged, per this class's best-effort contract.Two independent structure associations are reconciled per page: the page's own
/StructParents(the parent-tree key for its content marked-content sequences, i.e. tagged text/graphics), and each of its/Annotsentries' own/StructParent(the parent-tree key for that annotation specifically -- e.g. the/Formstructure element wrapping a form field'sWidget, or the/Linkelement wrapping a hyperlink'sLinkannotation). Missing the second one leaves such annotations in the merged output with no structure element referencing them at all -- present and functional, but invisible to assistive technology and a PDF/UA conformance failure.
-
finish
public COSObject finish()
Finalizes the merged tree: prunes any structure that ended up referencing pages that were never actually selected/cloned (e.g. a table spanning pages that were only partially selected), and returns the targetStructTreeRootreference to attach to the merged Catalog -- ornullif no selected page contributed any structure, so the caller can leave the merged document untagged entirely rather than emit a vacuousStructTreeRoot.
-
-