[
https://issues.apache.org/jira/browse/PDFBOX-6311?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Tilman Hausherr updated PDFBOX-6311:
------------------------------------
Component/s: Text extraction
> Fix nested marked content in actual text
> ----------------------------------------
>
> Key: PDFBOX-6311
> URL: https://issues.apache.org/jira/browse/PDFBOX-6311
> Project: PDFBox
> Issue Type: Bug
> Components: Text extraction
> Affects Versions: 3.0.8 PDFBox
> Reporter: Valery Bokov
> Priority: Major
> Labels: pull-request-available
>
> *Problem*
> _PDFTextStripper_ loses or leaks text when a marked-content sequence is
> nested in a sequence that has
> /ActualText:
> A nested sequence without /ActualText ends the replacement too early:
> _/Span <</ActualText (XYZ)>> BDC /Foo BMC (abc) Tj EMC (def) Tj EMC_
> Expected XYZ, but abc def is extracted (the ActualText is lost).
> A nested sequence with /ActualText ends the outer replacement when it ends:
> _/Span <</ActualText (X)>> BDC (a) Tj /Span <</ActualText (Y)>> BDC (b) Tj
> EMC (tail) Tj EMC_
> X Y tail is extracted: text that the outer ActualText replaces leaks into the
> output.
> *Cause*
> _currentMarkedContents_ is a stack, so that "another BDC within
> /ActualText... BDC block" doesn't cause confusion, but _actualText_ is a
> single field:
> - _beginMarkedContentSequence()_ overwrites it with the nested sequence's
> ActualText, which is null when the nested sequence doesn't have one.
> - _endMarkedContentSequence()_ sets it to null when any sequence with
> ActualText ends, including a nested one.
> *Fix*
> - A new field, {_}actualTextMarkedContent{_}, remembers the marked content
> that set actualText.
> - beginMarkedContentSequence()_ takes the ActualText only if no replacement
> is active. The outermost /ActualText wins, because it replaces all of its
> content, nested content included
> (ISO 32000-2, 14.9.4).
> - endMarkedContentSequence()_ resets _actualText_ only when that same marked
> content ends.
> _Note_: for nested /ActualText, the inner one is now ignored, so example 2
> extracts X.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]