Skip to content

Fix parent chain of structure element attribute dictionaries#104

Open
siebej wants to merge 1 commit into
apache:mainfrom
siebej:fix-structelem-attribute-parents
Open

Fix parent chain of structure element attribute dictionaries#104
siebej wants to merge 1 commit into
apache:mainfrom
siebej:fix-structelem-attribute-parents

Conversation

@siebej

@siebej siebej commented Jul 22, 2026

Copy link
Copy Markdown

PDFStructElem.attachAttributes builds the /A array with the PDFArray(List) constructor, which — unlike PDFArray.add() and PDFDictionary.put() — does not set the parent of its elements. The attribute dictionaries therefore cannot reach the PDFDocument through their parent chain.

This is currently latent: the existing table attributes (ColSpan, RowSpan, Scope) never need the document during serialization. But any string value inside an attribute dictionary (for example a Table /Headers attribute, or any attribute under encryption) crashes with IllegalStateException: Parent PDFDocument is unavailable as soon as a structure element carries more than one attribute dictionary. We hit this in production-like output with tagged tables.

The fix builds the array via add(), which does set parents. Includes a unit test that fails without the fix.

I don't have an ASF Jira account, so there is no FOP issue number yet — happy to reference one if a committer creates it.

Build the /A array via add() so that every attribute dictionary gets
this element as parent. The PDFArray(List) constructor does not set
parents, so any string value inside an attribute dictionary (such as
Table /Headers entries) crashes serialization with 'Parent PDFDocument
is unavailable' as soon as a structure element carries more than one
attribute dictionary (e.g. a span plus Headers).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant