File tree Expand file tree Collapse file tree
app/core/src/main/java/stirling/software/SPDF/pdf Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,7 +47,18 @@ protected void startPage(PDPage page) throws IOException {
4747 @ Override
4848 protected void writeString (String text , List <TextPosition > textPositions ) {
4949 pageTextBuilder .append (text );
50- pageTextPositions .addAll (textPositions );
50+ // Matches are located by indexing pageTextPositions with offsets into
51+ // pageTextBuilder, so the two must stay aligned character-for-character. A
52+ // TextPosition can decode to more than one character (ligatures such as "fi",
53+ // or any glyph with a multi-character ToUnicode mapping), so repeat it once
54+ // per character it contributes instead of adding it a single time.
55+ for (TextPosition position : textPositions ) {
56+ String unicode = position != null ? position .getUnicode () : null ;
57+ int charCount = unicode != null ? Math .max (1 , unicode .length ()) : 1 ;
58+ for (int i = 0 ; i < charCount ; i ++) {
59+ pageTextPositions .add (position );
60+ }
61+ }
5162 }
5263
5364 @ Override
You can’t perform that action at this time.
0 commit comments