Repository navigation
PDFBOX-6311: Fix nested marked content in actual text - #569
valerybokov wants to merge 2 commits into
Conversation
…ted in an ActualText sequence Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Text sequence Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Other issues. These are not execution errors, but it’s unclear whether this was done intentionally or by accident. 1 PDShadingType6 is public. It has a generatePatch method. But the class Patch is package private |
|
Re "other issues", I fixed the first one everywhere thanks. The third one I can't change, there is a usage and it's for the size of the list. So the actual type doesn't matter. This was package private in the past but there were two versions of the Plaintext class, now there is only one. |
closes #569 git-svn-id: https://svn.apache.org/repos/asf/pdfbox/branches/2.0@1940471 13f79535-47bb-0310-9956-ffa450edef68
closes #569 git-svn-id: https://svn.apache.org/repos/asf/pdfbox/branches/3.0@1940472 13f79535-47bb-0310-9956-ffa450edef68
Problem
PDFTextStripperloses or leaks text when a marked-content sequence is nested in a sequence that has/ActualText:A nested sequence without
/ActualTextends the replacement too early:Expected
XYZ, butabc defis extracted (the ActualText is lost).A nested sequence with
/ActualTextends the outer replacement when it ends:X Y tailis extracted: text that the outer ActualText replaces leaks into the output.Cause
currentMarkedContentsis a stack, so that "another BDC within /ActualText... BDC block" doesn'tcause confusion, but
actualTextis a single field:beginMarkedContentSequence()overwrites it with the nested sequence's ActualText, which isnullwhenthe nested sequence doesn't have one.
endMarkedContentSequence()sets it tonullwhen any sequence with ActualText ends, including anested one.
Fix
actualTextMarkedContent, remembers the marked content that setactualText.beginMarkedContentSequence()takes the ActualText only if no replacement is active. The outermost/ActualTextwins, because it replaces all of its content, nested content included(ISO 32000-2, 14.9.4).
endMarkedContentSequence()resetsactualTextonly when that same marked content ends.Note: for nested
/ActualText, the inner one is now ignored, so example 2 extractsX.Tests
TestTextStripper#testActualTextWithNestedMarkedContentandTestTextStripper#testNestedActualTextcoverthe two examples above. Both fail without the fix.
TestTextStripper,BidiTestandPDFTextStripperByAreaTestpass.Per https://www.apache.org/legal/generative-tooling.html: portions of this PR were
produced with assistance from Claude Code (Anthropic), based on a bug was described in Apache PDFBOX Issue Tracker.
I've reviewed the generated code and confirm to the best of my knowledge that the output does not include any
third-party copyrighted material and is compatible with the Apache License 2.0.