@syncfusion/ej2-pdf-data-extract 35.1.41 → 35.1.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * filename: index.d.ts
3
- * version : 35.1.41
3
+ * version : 35.1.43
4
4
  * Copyright Syncfusion Inc. 2001 - 2025. All rights reserved.
5
5
  * Use of this code is subject to the terms of our license.
6
6
  * A copy of the current license can be obtained at any time by e-mailing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncfusion/ej2-pdf-data-extract",
3
- "version": "35.1.41",
3
+ "version": "35.1.43",
4
4
  "description": "This repository provides advanced support for data extraction from PDF documents",
5
5
  "author": "Syncfusion Inc.",
6
6
  "license": "SEE LICENSE IN license",
@@ -10,7 +10,7 @@
10
10
  "dependencies": {
11
11
  "@syncfusion/ej2-base": "~35.1.37",
12
12
  "@syncfusion/ej2-compression": "~35.1.37",
13
- "@syncfusion/ej2-pdf": "~35.1.41"
13
+ "@syncfusion/ej2-pdf": "~35.1.43"
14
14
  },
15
15
  "devDependencies": {},
16
16
  "keywords": [
package/src/index.d.ts CHANGED
@@ -30,6 +30,7 @@ export * from './pdf-data-extract/core/pdf-text-parser';
30
30
  export * from './pdf-data-extract/core/text-structure';
31
31
  export * from './pdf-data-extract/core/pdf-structure-element';
32
32
  export * from './pdf-data-extract/core/utils';
33
+ export * from './pdf-data-extract/core/rtl-utils';
33
34
  export * from './pdf-data-extract/core/text-extraction/enumerator';
34
35
  export * from './pdf-data-extract/core/image-extraction/colorspace-utils';
35
36
  export * from './pdf-data-extract/core/image-extraction/colorspace';
package/src/index.js CHANGED
@@ -30,6 +30,7 @@ export * from './pdf-data-extract/core/pdf-text-parser';
30
30
  export * from './pdf-data-extract/core/text-structure';
31
31
  export * from './pdf-data-extract/core/pdf-structure-element';
32
32
  export * from './pdf-data-extract/core/utils';
33
+ export * from './pdf-data-extract/core/rtl-utils';
33
34
  export * from './pdf-data-extract/core/text-extraction/enumerator';
34
35
  export * from './pdf-data-extract/core/image-extraction/colorspace-utils';
35
36
  export * from './pdf-data-extract/core/image-extraction/colorspace';
@@ -854,6 +854,89 @@ export declare class PdfDataExtractor {
854
854
  * ```
855
855
  */
856
856
  findTextSync(searchText: string[], options?: TextSearchOptions): TextSearchResult[];
857
+ /**
858
+ * Rebuilds the plain-text extraction result in logical RTL reading order.
859
+ * Non-RTL documents keep the existing flat text. RTL documents are rebuilt
860
+ * from the line pipeline so rows are read top-to-bottom and RTL rows are
861
+ * emitted right-to-left, matching Adobe extraction order.
862
+ *
863
+ * @private
864
+ * @param {number} startIndex - Start page index of the extraction.
865
+ * @param {number} endIndex - End page index of the extraction.
866
+ * @param {string} flatText - Flat extracted text in stream order.
867
+ * @returns {string} Reading-order text for RTL documents, otherwise flatText.
868
+ */
869
+ private _buildRtlReadingText;
870
+ /**
871
+ * Asynchronous variant of `_buildRtlReadingText`.
872
+ *
873
+ * @private
874
+ * @param {number} startIndex - Start page index of the extraction.
875
+ * @param {number} endIndex - End page index of the extraction.
876
+ * @param {string} flatText - Flat extracted text in stream order.
877
+ * @returns {Promise<string>} Reading-order text for RTL documents, otherwise flatText.
878
+ */
879
+ private _buildRtlReadingTextAsync;
880
+ private _normalizeTextLines;
881
+ /**
882
+ * Computes the vertical tolerance used to decide whether two text lines
883
+ * share the same baseline (fraction of the dominant line height).
884
+ *
885
+ * @private
886
+ * @param {TextLine[]} textLines - Lines being merged.
887
+ * @returns {number} Row-grouping tolerance in page units.
888
+ */
889
+ private _getMergeRowTolerance;
890
+ /**
891
+ * Determines whether two line bounds share the same baseline row.
892
+ *
893
+ * @private
894
+ * @param {Rectangle} first - First line bounds.
895
+ * @param {Rectangle} second - Second line bounds.
896
+ * @param {number} tolerance - Vertical tolerance for row grouping.
897
+ * @returns {boolean} True when both lines are on the same baseline row.
898
+ */
899
+ private _isSameRtlRowLine;
900
+ /**
901
+ * Determines whether the horizontal gap between two same-baseline lines is
902
+ * small enough to treat them as words of the same visual line. Large gaps
903
+ * (columns, tab-separated figures) are kept as separate lines.
904
+ *
905
+ * @private
906
+ * @param {Rectangle} previous - Bounds of the already merged line.
907
+ * @param {Rectangle} current - Bounds of the candidate line to merge.
908
+ * @param {number} tolerance - Row tolerance used as the gap scale.
909
+ * @returns {boolean} True when the gap indicates words of one visual line.
910
+ */
911
+ private _isAdjacentWordGap;
912
+ /**
913
+ * Computes the union of two line bounds.
914
+ *
915
+ * @private
916
+ * @param {Rectangle} first - First line bounds.
917
+ * @param {Rectangle} second - Second line bounds.
918
+ * @returns {Rectangle} Union bounds covering both lines.
919
+ */
920
+ private _getMergedBounds;
921
+ /**
922
+ * Normalizes a single text line (and its words) from visual RTL order into
923
+ * logical reading order, sorting RTL words right-to-left by position when
924
+ * the line advances leftward.
925
+ *
926
+ * @private
927
+ * @param {TextLine} textLine - Line to normalize.
928
+ * @returns {void}
929
+ */
930
+ private _normalizeRtlTextLine;
931
+ /**
932
+ * Determines whether the words of a line advance leftward (visual RTL order)
933
+ * by comparing the bounds of consecutive words.
934
+ *
935
+ * @private
936
+ * @param {TextWord[]} words - Line words in stream order.
937
+ * @returns {boolean} True when consecutive words are placed right-to-left.
938
+ */
939
+ private _isLineAdvancingLeftward;
857
940
  /**
858
941
  * Coordinates document-wide text search and returns the search results for all supplied search strings.
859
942
  *
@@ -40,6 +40,7 @@ import { _GraphicState } from './graphic-state';
40
40
  import { PdfTagType } from './text-extraction/enumerator';
41
41
  import { _TextProcessingMode } from './enum';
42
42
  import { _addFontResources, _getXObject, _getXObjectResources, _ignoreEscapeSequence, _isArrayEqual, _parseEncodedText } from './utils';
43
+ import { _normalizeRtlText, _normalizeSearchText, _containsRtlCharacter, _containsArabicPresentationForm, _isVisualOrderRtl, _reorderFragmentsForRtlReading, _mapArabicPresentationForms, _invertVisualLtrFragment, _resolveMirroredBrackets } from './rtl-utils';
43
44
  import { _PdfDictionary, PdfPath, _ContentParser, PdfRotationAngle } from '@syncfusion/ej2-pdf';
44
45
  import { _PdfTextParser } from './pdf-text-parser';
45
46
  import { PdfStructureElement } from './pdf-structure-element';
@@ -290,15 +291,16 @@ var PdfDataExtractor = /** @class */ (function () {
290
291
  this._processPages(startIndex, endIndex);
291
292
  if (this._resultantText.length) {
292
293
  this._resultantText = _ignoreEscapeSequence(this._resultantText);
294
+ this._resultantText = this._buildRtlReadingText(startIndex, endIndex, this._resultantText);
293
295
  }
294
296
  this._isLayout = false;
295
297
  return this._resultantText;
296
298
  };
297
299
  PdfDataExtractor.prototype.extractText = function (options) {
298
300
  return __awaiter(this, void 0, void 0, function () {
299
- var startIndex, endIndex;
300
- return __generator(this, function (_a) {
301
- switch (_a.label) {
301
+ var startIndex, endIndex, _a;
302
+ return __generator(this, function (_b) {
303
+ switch (_b.label) {
302
304
  case 0:
303
305
  initializeTelemetryFeature('ExtractText', 'PDFLibrary');
304
306
  startIndex = 0;
@@ -318,10 +320,15 @@ var PdfDataExtractor = /** @class */ (function () {
318
320
  }
319
321
  return [4 /*yield*/, this._processPdfPages(startIndex, endIndex)];
320
322
  case 1:
321
- _a.sent();
322
- if (this._resultantText.length) {
323
- this._resultantText = _ignoreEscapeSequence(this._resultantText);
324
- }
323
+ _b.sent();
324
+ if (!this._resultantText.length) return [3 /*break*/, 3];
325
+ this._resultantText = _ignoreEscapeSequence(this._resultantText);
326
+ _a = this;
327
+ return [4 /*yield*/, this._buildRtlReadingTextAsync(startIndex, endIndex, this._resultantText)];
328
+ case 2:
329
+ _a._resultantText = _b.sent();
330
+ _b.label = 3;
331
+ case 3:
325
332
  this._isLayout = false;
326
333
  return [2 /*return*/, this._resultantText];
327
334
  }
@@ -1711,6 +1718,7 @@ var PdfDataExtractor = /** @class */ (function () {
1711
1718
  this._textLine = [];
1712
1719
  this._processPages(startIndex, endIndex);
1713
1720
  this._isExtractTextLines = false;
1721
+ this._normalizeTextLines(this._textLine);
1714
1722
  return this._textLine;
1715
1723
  };
1716
1724
  PdfDataExtractor.prototype.extractTextLines = function (options) {
@@ -1735,6 +1743,7 @@ var PdfDataExtractor = /** @class */ (function () {
1735
1743
  case 1:
1736
1744
  _a.sent();
1737
1745
  this._isExtractTextLines = false;
1746
+ this._normalizeTextLines(this._textLine);
1738
1747
  return [2 /*return*/, this._textLine];
1739
1748
  }
1740
1749
  });
@@ -1831,6 +1840,311 @@ var PdfDataExtractor = /** @class */ (function () {
1831
1840
  }
1832
1841
  return textSearchResults[0];
1833
1842
  };
1843
+ /**
1844
+ * Rebuilds the plain-text extraction result in logical RTL reading order.
1845
+ * Non-RTL documents keep the existing flat text. RTL documents are rebuilt
1846
+ * from the line pipeline so rows are read top-to-bottom and RTL rows are
1847
+ * emitted right-to-left, matching Adobe extraction order.
1848
+ *
1849
+ * @private
1850
+ * @param {number} startIndex - Start page index of the extraction.
1851
+ * @param {number} endIndex - End page index of the extraction.
1852
+ * @param {string} flatText - Flat extracted text in stream order.
1853
+ * @returns {string} Reading-order text for RTL documents, otherwise flatText.
1854
+ */
1855
+ PdfDataExtractor.prototype._buildRtlReadingText = function (startIndex, endIndex, flatText) {
1856
+ if (!_containsRtlCharacter(flatText)) {
1857
+ return flatText;
1858
+ }
1859
+ var textLines = this.extractTextLinesSync({ startPageIndex: startIndex, endPageIndex: endIndex });
1860
+ if (!textLines || textLines.length === 0) {
1861
+ return _normalizeRtlText(flatText);
1862
+ }
1863
+ var result = '';
1864
+ for (var i = 0; i < textLines.length; i++) {
1865
+ var textLine = textLines[Number.parseInt(i.toString(), 10)];
1866
+ result += textLine._text;
1867
+ if (i < textLines.length - 1) {
1868
+ result += '\r\n';
1869
+ }
1870
+ }
1871
+ return result;
1872
+ };
1873
+ /**
1874
+ * Asynchronous variant of `_buildRtlReadingText`.
1875
+ *
1876
+ * @private
1877
+ * @param {number} startIndex - Start page index of the extraction.
1878
+ * @param {number} endIndex - End page index of the extraction.
1879
+ * @param {string} flatText - Flat extracted text in stream order.
1880
+ * @returns {Promise<string>} Reading-order text for RTL documents, otherwise flatText.
1881
+ */
1882
+ PdfDataExtractor.prototype._buildRtlReadingTextAsync = function (startIndex, endIndex, flatText) {
1883
+ return __awaiter(this, void 0, void 0, function () {
1884
+ var textLines, result, i, textLine;
1885
+ return __generator(this, function (_a) {
1886
+ switch (_a.label) {
1887
+ case 0:
1888
+ if (!_containsRtlCharacter(flatText)) {
1889
+ return [2 /*return*/, flatText];
1890
+ }
1891
+ return [4 /*yield*/, this.extractTextLines({ startPageIndex: startIndex, endPageIndex: endIndex })];
1892
+ case 1:
1893
+ textLines = _a.sent();
1894
+ if (!textLines || textLines.length === 0) {
1895
+ return [2 /*return*/, _normalizeRtlText(flatText)];
1896
+ }
1897
+ result = '';
1898
+ for (i = 0; i < textLines.length; i++) {
1899
+ textLine = textLines[Number.parseInt(i.toString(), 10)];
1900
+ result += textLine._text;
1901
+ if (i < textLines.length - 1) {
1902
+ result += '\r\n';
1903
+ }
1904
+ }
1905
+ return [2 /*return*/, result];
1906
+ }
1907
+ });
1908
+ });
1909
+ };
1910
+ PdfDataExtractor.prototype._normalizeTextLines = function (textLines) {
1911
+ if (!textLines || textLines.length === 0) {
1912
+ return;
1913
+ }
1914
+ var fragments = [];
1915
+ for (var i = 0; i < textLines.length; i++) {
1916
+ var textLine = textLines[Number.parseInt(i.toString(), 10)];
1917
+ if (textLine && textLine._text && textLine._bounds) {
1918
+ fragments.push({ text: textLine._text, bounds: textLine._bounds });
1919
+ }
1920
+ }
1921
+ var rowOrder = [];
1922
+ if (fragments.length === textLines.length) {
1923
+ var ordered = _reorderFragmentsForRtlReading(fragments);
1924
+ var consumed = new Array(textLines.length).fill(false);
1925
+ for (var f = 0; f < ordered.length; f++) {
1926
+ var fragment = ordered[Number.parseInt(f.toString(), 10)];
1927
+ for (var i = 0; i < textLines.length; i++) {
1928
+ if (consumed[Number.parseInt(i.toString(), 10)]) {
1929
+ continue;
1930
+ }
1931
+ var textLine = textLines[Number.parseInt(i.toString(), 10)];
1932
+ if (textLine._text === fragment.text && textLine._bounds === fragment.bounds) {
1933
+ rowOrder.push(textLine);
1934
+ consumed[Number.parseInt(i.toString(), 10)] = true;
1935
+ break;
1936
+ }
1937
+ }
1938
+ }
1939
+ }
1940
+ var orderedLines = rowOrder.length === textLines.length ? rowOrder : textLines;
1941
+ for (var i = 0; i < orderedLines.length; i++) {
1942
+ var textLine = orderedLines[Number.parseInt(i.toString(), 10)];
1943
+ this._normalizeRtlTextLine(textLine);
1944
+ }
1945
+ var tolerance = this._getMergeRowTolerance(orderedLines);
1946
+ var mergedLines = [];
1947
+ for (var i = 0; i < orderedLines.length; i++) {
1948
+ var textLine = orderedLines[Number.parseInt(i.toString(), 10)];
1949
+ var previous = mergedLines.length > 0 ?
1950
+ mergedLines[Number.parseInt((mergedLines.length - 1).toString(), 10)] : null;
1951
+ var rowHasRtl = _containsRtlCharacter(previous ? previous._text : '') ||
1952
+ _containsRtlCharacter(textLine._text);
1953
+ if (previous && rowHasRtl && this._isSameRtlRowLine(previous._bounds, textLine._bounds, tolerance) &&
1954
+ this._isAdjacentWordGap(previous._bounds, textLine._bounds, tolerance)) {
1955
+ var needsSpace = previous._text.length > 0 && textLine._text.length > 0 &&
1956
+ previous._text[Number.parseInt((previous._text.length - 1).toString(), 10)] !== ' ' &&
1957
+ textLine._text[0] !== ' ';
1958
+ previous._text += (needsSpace ? ' ' : '') + textLine._text;
1959
+ if (textLine._wordCollection) {
1960
+ for (var j = 0; j < textLine._wordCollection.length; j++) {
1961
+ previous._wordCollection.push(textLine._wordCollection[Number.parseInt(j.toString(), 10)]);
1962
+ }
1963
+ }
1964
+ previous._bounds = this._getMergedBounds(previous._bounds, textLine._bounds);
1965
+ }
1966
+ else {
1967
+ mergedLines.push(textLine);
1968
+ }
1969
+ }
1970
+ if (mergedLines.length !== textLines.length) {
1971
+ for (var i = 0; i < mergedLines.length; i++) {
1972
+ textLines[Number.parseInt(i.toString(), 10)] = mergedLines[Number.parseInt(i.toString(), 10)];
1973
+ }
1974
+ textLines.length = mergedLines.length;
1975
+ }
1976
+ };
1977
+ /**
1978
+ * Computes the vertical tolerance used to decide whether two text lines
1979
+ * share the same baseline (fraction of the dominant line height).
1980
+ *
1981
+ * @private
1982
+ * @param {TextLine[]} textLines - Lines being merged.
1983
+ * @returns {number} Row-grouping tolerance in page units.
1984
+ */
1985
+ PdfDataExtractor.prototype._getMergeRowTolerance = function (textLines) {
1986
+ var totalHeight = 0;
1987
+ var count = 0;
1988
+ for (var i = 0; i < textLines.length; i++) {
1989
+ var textLine = textLines[Number.parseInt(i.toString(), 10)];
1990
+ if (textLine && textLine._bounds && textLine._bounds.height > 0) {
1991
+ totalHeight += textLine._bounds.height;
1992
+ count++;
1993
+ }
1994
+ }
1995
+ if (count === 0) {
1996
+ return 2;
1997
+ }
1998
+ return Math.max(2, (totalHeight / count) * 0.5);
1999
+ };
2000
+ /**
2001
+ * Determines whether two line bounds share the same baseline row.
2002
+ *
2003
+ * @private
2004
+ * @param {Rectangle} first - First line bounds.
2005
+ * @param {Rectangle} second - Second line bounds.
2006
+ * @param {number} tolerance - Vertical tolerance for row grouping.
2007
+ * @returns {boolean} True when both lines are on the same baseline row.
2008
+ */
2009
+ PdfDataExtractor.prototype._isSameRtlRowLine = function (first, second, tolerance) {
2010
+ if (!first || !second) {
2011
+ return false;
2012
+ }
2013
+ var firstCenter = first.y + first.height / 2;
2014
+ var secondCenter = second.y + second.height / 2;
2015
+ return Math.abs(firstCenter - secondCenter) <= tolerance;
2016
+ };
2017
+ /**
2018
+ * Determines whether the horizontal gap between two same-baseline lines is
2019
+ * small enough to treat them as words of the same visual line. Large gaps
2020
+ * (columns, tab-separated figures) are kept as separate lines.
2021
+ *
2022
+ * @private
2023
+ * @param {Rectangle} previous - Bounds of the already merged line.
2024
+ * @param {Rectangle} current - Bounds of the candidate line to merge.
2025
+ * @param {number} tolerance - Row tolerance used as the gap scale.
2026
+ * @returns {boolean} True when the gap indicates words of one visual line.
2027
+ */
2028
+ PdfDataExtractor.prototype._isAdjacentWordGap = function (previous, current, tolerance) {
2029
+ if (!previous || !current) {
2030
+ return false;
2031
+ }
2032
+ var gap = Math.max(previous.x - (current.x + current.width), current.x - (previous.x + previous.width));
2033
+ return gap < Math.max(24, tolerance * 8);
2034
+ };
2035
+ /**
2036
+ * Computes the union of two line bounds.
2037
+ *
2038
+ * @private
2039
+ * @param {Rectangle} first - First line bounds.
2040
+ * @param {Rectangle} second - Second line bounds.
2041
+ * @returns {Rectangle} Union bounds covering both lines.
2042
+ */
2043
+ PdfDataExtractor.prototype._getMergedBounds = function (first, second) {
2044
+ if (!first) {
2045
+ return second;
2046
+ }
2047
+ if (!second) {
2048
+ return first;
2049
+ }
2050
+ var x = Math.min(first.x, second.x);
2051
+ var y = Math.min(first.y, second.y);
2052
+ return {
2053
+ x: x,
2054
+ y: y,
2055
+ width: Math.max(first.x + first.width, second.x + second.width) - x,
2056
+ height: Math.max(first.y + first.height, second.y + second.height) - y
2057
+ };
2058
+ };
2059
+ /**
2060
+ * Normalizes a single text line (and its words) from visual RTL order into
2061
+ * logical reading order, sorting RTL words right-to-left by position when
2062
+ * the line advances leftward.
2063
+ *
2064
+ * @private
2065
+ * @param {TextLine} textLine - Line to normalize.
2066
+ * @returns {void}
2067
+ */
2068
+ PdfDataExtractor.prototype._normalizeRtlTextLine = function (textLine) {
2069
+ var words = textLine._wordCollection;
2070
+ if (!textLine._text || !_containsRtlCharacter(textLine._text)) {
2071
+ return;
2072
+ }
2073
+ var isVisualOrder = _containsArabicPresentationForm(textLine._text) ||
2074
+ this._isLineAdvancingLeftward(words);
2075
+ var changed = false;
2076
+ if (words && words.length > 1 && isVisualOrder) {
2077
+ var orderedWords = words.slice().sort(function (a, b) { return b._bounds.x - a._bounds.x; });
2078
+ for (var j = 0; j < orderedWords.length; j++) {
2079
+ if (orderedWords[Number.parseInt(j.toString(), 10)] !== words[Number.parseInt(j.toString(), 10)]) {
2080
+ changed = true;
2081
+ break;
2082
+ }
2083
+ }
2084
+ if (changed) {
2085
+ for (var j = 0; j < orderedWords.length; j++) {
2086
+ words[Number.parseInt(j.toString(), 10)] = orderedWords[Number.parseInt(j.toString(), 10)];
2087
+ }
2088
+ }
2089
+ }
2090
+ for (var j = 0; j < (words ? words.length : 0); j++) {
2091
+ var textWord = words[Number.parseInt(j.toString(), 10)];
2092
+ if (!textWord || !textWord._text) {
2093
+ continue;
2094
+ }
2095
+ if (_containsRtlCharacter(textWord._text)) {
2096
+ textWord._text = _normalizeRtlText(textWord._text);
2097
+ }
2098
+ else if (isVisualOrder) {
2099
+ textWord._text = _invertVisualLtrFragment(textWord._text);
2100
+ }
2101
+ }
2102
+ if (changed) {
2103
+ var rebuilt = '';
2104
+ for (var j = 0; j < words.length; j++) {
2105
+ rebuilt += words[Number.parseInt(j.toString(), 10)]._text;
2106
+ }
2107
+ textLine._text = rebuilt;
2108
+ }
2109
+ else if (isVisualOrder) {
2110
+ textLine._text = _normalizeRtlText(textLine._text);
2111
+ }
2112
+ else {
2113
+ textLine._text = _mapArabicPresentationForms(textLine._text);
2114
+ }
2115
+ if (isVisualOrder) {
2116
+ textLine._text = _resolveMirroredBrackets(textLine._text);
2117
+ }
2118
+ };
2119
+ /**
2120
+ * Determines whether the words of a line advance leftward (visual RTL order)
2121
+ * by comparing the bounds of consecutive words.
2122
+ *
2123
+ * @private
2124
+ * @param {TextWord[]} words - Line words in stream order.
2125
+ * @returns {boolean} True when consecutive words are placed right-to-left.
2126
+ */
2127
+ PdfDataExtractor.prototype._isLineAdvancingLeftward = function (words) {
2128
+ if (!words || words.length < 2) {
2129
+ return false;
2130
+ }
2131
+ var rightward = 0;
2132
+ var leftward = 0;
2133
+ for (var i = 1; i < words.length; i++) {
2134
+ var previous = words[Number.parseInt((i - 1).toString(), 10)];
2135
+ var current = words[Number.parseInt(i.toString(), 10)];
2136
+ if (!previous._bounds || !current._bounds) {
2137
+ continue;
2138
+ }
2139
+ if (_isVisualOrderRtl(previous._bounds, current._bounds)) {
2140
+ rightward++;
2141
+ }
2142
+ else if (current._bounds.x < previous._bounds.x) {
2143
+ leftward++;
2144
+ }
2145
+ }
2146
+ return leftward === 0 && rightward > 0;
2147
+ };
1834
2148
  /**
1835
2149
  * Coordinates document-wide text search and returns the search results for all supplied search strings.
1836
2150
  *
@@ -1903,7 +2217,8 @@ var PdfDataExtractor = /** @class */ (function () {
1903
2217
  var page = this._document.getPage(pageIndex);
1904
2218
  for (var i = 0; i < searchTextCollection.length; i++) {
1905
2219
  var searchText = searchTextCollection[Number.parseInt(i.toString(), 10)];
1906
- var searchTextLower = options.caseSensitive ? searchText : searchText.toLowerCase();
2220
+ var normalizedSearchText = _normalizeSearchText(searchText);
2221
+ var searchTextLower = options.caseSensitive ? normalizedSearchText : normalizedSearchText.toLowerCase();
1907
2222
  searchTextLowerCollection.push(searchTextLower);
1908
2223
  boundsCollection.set(i, []);
1909
2224
  }
@@ -1936,6 +2251,7 @@ var PdfDataExtractor = /** @class */ (function () {
1936
2251
  }
1937
2252
  else {
1938
2253
  var startIndex = 0;
2254
+ var isRtlWord = _containsRtlCharacter(wordText);
1939
2255
  while (true) { // eslint-disable-line
1940
2256
  var matchIndex = wordText.indexOf(searchTextLower, startIndex);
1941
2257
  if (matchIndex === -1) {
@@ -1951,6 +2267,14 @@ var PdfDataExtractor = /** @class */ (function () {
1951
2267
  }
1952
2268
  charIndex++;
1953
2269
  }
2270
+ if (isRtlWord && glyphs.length === wordText.length) {
2271
+ matchGlyphs.length = 0;
2272
+ var glyphStart = glyphs.length - endIndex;
2273
+ var glyphEnd = glyphs.length - matchIndex;
2274
+ for (var i = glyphStart; i < glyphEnd; i++) {
2275
+ matchGlyphs.push(glyphs[Number.parseInt(i.toString(), 10)]);
2276
+ }
2277
+ }
1954
2278
  if (matchGlyphs.length > 0) {
1955
2279
  var pdfPath = new PdfPath();
1956
2280
  for (var i = 0; i < matchGlyphs.length; i++) {
@@ -414,8 +414,12 @@ var _PdfRedactionProcessor = /** @class */ (function () {
414
414
  var inkAnnotation = annotation;
415
415
  var inkList = inkAnnotation.inkPointsCollection;
416
416
  var inkPointsToNumberArray = _convertPointsToNumberArrays(inkList);
417
- inkBounds = this._getBoundsFromPoints(inkPointsToNumberArray[0], page);
418
- bounds = inkAnnotation.bounds;
417
+ var inkStrokePoints = [];
418
+ for (var stroke = 0; stroke < inkPointsToNumberArray.length; stroke++) {
419
+ inkStrokePoints = inkStrokePoints.concat(inkPointsToNumberArray[Number.parseInt(stroke.toString(), 10)]);
420
+ }
421
+ inkBounds = this._getBoundsFromPoints(inkStrokePoints, page);
422
+ bounds = inkPointsToNumberArray.length > 0 ? inkBounds.bounds : inkAnnotation.bounds;
419
423
  if (!inkAnnotation._isLoaded) {
420
424
  inkBounds.isValidAnnotation = true;
421
425
  }