@syncfusion/ej2-pdf 24.2.7 → 24.2.9

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.
@@ -9325,6 +9325,13 @@ var PdfField = /** @__PURE__ @class */ (function () {
9325
9325
  this._textAlignment = value;
9326
9326
  this._stringFormat = new PdfStringFormat(value, PdfVerticalAlignment.middle);
9327
9327
  };
9328
+ PdfField.prototype._parseItems = function () {
9329
+ var collection = [];
9330
+ for (var i = 0; i < this.itemsCount; i++) {
9331
+ collection.push(this.itemAt(i));
9332
+ }
9333
+ return collection;
9334
+ };
9328
9335
  return PdfField;
9329
9336
  }());
9330
9337
  /**
@@ -40929,18 +40936,24 @@ var _PdfCrossReference = /** @__PURE__ @class */ (function () {
40929
40936
  }
40930
40937
  }
40931
40938
  var hasRoot = false;
40939
+ var root;
40932
40940
  try {
40933
- var root = trailerDictionary.get('Root');
40934
- if (root) {
40941
+ root = trailerDictionary.get('Root');
40942
+ }
40943
+ catch (e) {
40944
+ throw new BaseException('Invalid cross reference', 'XRefParseException');
40945
+ }
40946
+ if (root) {
40947
+ try {
40935
40948
  var pagesEntry = root.get('Pages');
40936
40949
  if (pagesEntry) {
40937
40950
  this._root = root;
40938
40951
  hasRoot = true;
40939
40952
  }
40940
40953
  }
40941
- }
40942
- catch (ex) {
40943
- throw new BaseException('Invalid cross reference', 'InvalidXRef');
40954
+ catch (ex) {
40955
+ throw new BaseException('Invalid cross reference', 'InvalidXRef');
40956
+ }
40944
40957
  }
40945
40958
  if (!hasRoot) {
40946
40959
  if (!recoveryMode) {
@@ -42296,7 +42309,7 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42296
42309
  for (var i = 0; i < this._fieldCollection.length; i++) {
42297
42310
  var field = this._fieldCollection[Number.parseInt(i.toString(), 10)];
42298
42311
  if (field.page) {
42299
- var index = _getPageIndex(document_1, field.page._pageDictionary);
42312
+ var index = _getPageIndex(document_1, this._sortItemByPageIndex(field, true)._pageDictionary);
42300
42313
  if (index >= 0) {
42301
42314
  if (fieldCollection.has(index)) {
42302
42315
  value = fieldCollection.get(index);
@@ -42320,16 +42333,18 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42320
42333
  var fieldsCount_1 = 0;
42321
42334
  fieldCollection.forEach(function (value, key) {
42322
42335
  _this._tabOrder = _this._tabCollection.get(key);
42323
- var fields = value;
42324
- fields.sort(function (pdfField1, pdfField2) {
42325
- return _this._compareFields(pdfField1, pdfField2);
42326
- });
42327
- for (var j = 0; j < fields.length; j++) {
42328
- var fieldIndex = _this._fieldCollection.indexOf(fields[Number.parseInt(j.toString(), 10)]);
42329
- if (fieldIndex !== -1 && fieldIndex !== fieldsCount_1 + j) {
42330
- var field = _this._fieldCollection[Number.parseInt(fieldIndex.toString(), 10)];
42331
- _this._fieldCollection.splice(fieldIndex, 1);
42332
- _this._fieldCollection.splice(fieldsCount_1 + j, 0, field);
42336
+ if (_this._tabOrder !== PdfFormFieldsTabOrder.structure) {
42337
+ var fields = value;
42338
+ fields.sort(function (pdfField1, pdfField2) {
42339
+ return _this._compareFields(pdfField1, pdfField2);
42340
+ });
42341
+ for (var j = 0; j < fields.length; j++) {
42342
+ var fieldIndex = _this._fieldCollection.indexOf(fields[Number.parseInt(j.toString(), 10)]);
42343
+ if (fieldIndex !== -1 && fieldIndex !== fieldsCount_1 + j) {
42344
+ var field = _this._fieldCollection[Number.parseInt(fieldIndex.toString(), 10)];
42345
+ _this._fieldCollection.splice(fieldIndex, 1);
42346
+ _this._fieldCollection.splice(fieldsCount_1 + j, 0, field);
42347
+ }
42333
42348
  }
42334
42349
  }
42335
42350
  fieldsCount_1 += value.length;
@@ -42569,10 +42584,24 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42569
42584
  var page1 = field1.page;
42570
42585
  var page2 = field2.page;
42571
42586
  if (page1 && page1 instanceof PdfPage && page2 && page2 instanceof PdfPage) {
42572
- var page1Index = page1._pageIndex;
42573
- var page2Index = page2._pageIndex;
42574
- var rectangle1 = this._getRectangle(field1._dictionary);
42575
- var rectangle2 = this._getRectangle(field2._dictionary);
42587
+ var page1Index = this._sortItemByPageIndex(field1, false)._pageIndex;
42588
+ var page2Index = this._sortItemByPageIndex(field2, false)._pageIndex;
42589
+ var rectangle1 = void 0;
42590
+ if (field1._dictionary.has('Kids')) {
42591
+ rectangle1 = this._getItemRectangle(field1);
42592
+ }
42593
+ else {
42594
+ rectangle1 = this._getRectangle(field1._dictionary);
42595
+ }
42596
+ var rectangle2 = void 0;
42597
+ if (field2._dictionary.has('Kids')) {
42598
+ rectangle2 = this._getItemRectangle(field2);
42599
+ }
42600
+ else {
42601
+ rectangle2 = this._getRectangle(field2._dictionary);
42602
+ }
42603
+ var firstHeight = rectangle1[3] - rectangle1[1];
42604
+ var secondHeight = rectangle2[3] - rectangle2[1];
42576
42605
  if (rectangle1 && rectangle1.length >= 2 && rectangle2 && rectangle2.length >= 2) {
42577
42606
  var x1 = rectangle1[0];
42578
42607
  var y1 = rectangle1[1];
@@ -42583,6 +42612,13 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42583
42612
  index = page1Index - page2Index;
42584
42613
  if (this._tabOrder === PdfFormFieldsTabOrder.row) {
42585
42614
  xdiff = this._compare(y2, y1);
42615
+ if (xdiff !== 0) {
42616
+ var isValid = xdiff === -1 && y1 > y2 && (y1 - firstHeight / 2) < y2;
42617
+ isValid = isValid || (xdiff === 1 && y2 > y1 && (y2 - secondHeight / 2) < y1);
42618
+ if (isValid) {
42619
+ xdiff = 0;
42620
+ }
42621
+ }
42586
42622
  if (index !== 0) {
42587
42623
  result = index;
42588
42624
  }
@@ -42625,28 +42661,32 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42625
42661
  return result;
42626
42662
  };
42627
42663
  PdfForm.prototype._getRectangle = function (dictionary) {
42628
- var _this = this;
42664
+ var rect;
42629
42665
  if (dictionary.has('Rect')) {
42630
- var rect = dictionary.get('Rect');
42631
- if (rect) {
42632
- return rect;
42633
- }
42666
+ rect = dictionary.getArray('Rect');
42634
42667
  }
42635
- else {
42636
- if (dictionary.has('Kids')) {
42637
- var kidsArray = dictionary.get('Kids');
42638
- if (kidsArray) {
42639
- if (kidsArray.length > 1) {
42640
- kidsArray.sort(function (x, y) {
42641
- return _this._compareKidsElement(x, y);
42642
- });
42668
+ return rect;
42669
+ };
42670
+ PdfForm.prototype._getItemRectangle = function (field) {
42671
+ var result;
42672
+ var dictionary = field._dictionary;
42673
+ if (dictionary.has('Kids')) {
42674
+ var kids = dictionary.getArray('Kids');
42675
+ if (kids && kids.length >= 1) {
42676
+ if (kids.length === 1) {
42677
+ result = this._getRectangle(kids[0]);
42678
+ }
42679
+ else {
42680
+ if (field && field.itemsCount > 1) {
42681
+ result = this._getRectangle(field.itemAt(0)._dictionary);
42682
+ }
42683
+ else {
42684
+ result = this._getRectangle(kids[0]);
42643
42685
  }
42644
- var dictionary_1 = this._crossReference._fetch(kidsArray[0]);
42645
- return this._getRectangle(dictionary_1);
42646
42686
  }
42647
42687
  }
42648
42688
  }
42649
- return null;
42689
+ return result;
42650
42690
  };
42651
42691
  PdfForm.prototype._compare = function (x, y) {
42652
42692
  if (x > y) {
@@ -42664,6 +42704,7 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42664
42704
  var yDictionary = this._crossReference._fetch(y);
42665
42705
  var xRect = this._getRectangle(xDictionary);
42666
42706
  var yRect = this._getRectangle(yDictionary);
42707
+ var result;
42667
42708
  if (xRect && xRect.length >= 2 && yRect && yRect.length >= 2) {
42668
42709
  var x1 = xRect[0];
42669
42710
  var y1 = xRect[1];
@@ -42671,7 +42712,6 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42671
42712
  var y2 = yRect[1];
42672
42713
  if (typeof x1 === 'number' && typeof x2 === 'number' &&
42673
42714
  typeof y1 === 'number' && typeof y2 === 'number') {
42674
- var result = 0;
42675
42715
  var xdiff = void 0;
42676
42716
  if (this._tabOrder === PdfFormFieldsTabOrder.row) {
42677
42717
  xdiff = this._compare(y2, y1);
@@ -42691,10 +42731,90 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42691
42731
  result = this._compare(y2, y1);
42692
42732
  }
42693
42733
  }
42734
+ else {
42735
+ result = 0;
42736
+ }
42694
42737
  return result;
42695
42738
  }
42696
42739
  }
42697
- return null;
42740
+ return result;
42741
+ };
42742
+ PdfForm.prototype._sortItemByPageIndex = function (field, hasPageTabOrder) {
42743
+ var page = field.page;
42744
+ var tabOrder = this._tabOrder;
42745
+ this._tabOrder = hasPageTabOrder ? field.page.tabOrder : tabOrder;
42746
+ this._sortFieldItems(field);
42747
+ if (field._isLoaded && field._kidsCount > 1) {
42748
+ page = field.itemAt(0).page;
42749
+ }
42750
+ this._tabOrder = tabOrder;
42751
+ if (typeof page === 'undefined') {
42752
+ page = field.page;
42753
+ }
42754
+ return page;
42755
+ };
42756
+ PdfForm.prototype._sortFieldItems = function (field) {
42757
+ var _this = this;
42758
+ if (field._isLoaded && (field instanceof PdfTextBoxField ||
42759
+ field instanceof PdfListBoxField ||
42760
+ field instanceof PdfCheckBoxField ||
42761
+ field instanceof PdfRadioButtonListField)) {
42762
+ var collection = field._parseItems(); // eslint-disable-line
42763
+ collection.sort(function (item1, item2) {
42764
+ return _this._compareFieldItem(item1, item2);
42765
+ });
42766
+ field._parsedItems.clear();
42767
+ for (var i = 0; i < collection.length; i++) {
42768
+ field._parsedItems.set(i, collection[Number.parseInt(i.toString(), 10)]);
42769
+ }
42770
+ }
42771
+ };
42772
+ PdfForm.prototype._compareFieldItem = function (item1, item2) {
42773
+ var result = 0;
42774
+ if (typeof item1 !== 'undefined' && typeof item2 !== 'undefined') {
42775
+ var page1 = item1.page;
42776
+ var page2 = item2.page;
42777
+ var array1 = this._getRectangle(item1._dictionary);
42778
+ var array2 = this._getRectangle(item2._dictionary);
42779
+ if (array1 && array2) {
42780
+ var x1 = array1[0];
42781
+ var y1 = array1[1];
42782
+ var x2 = array2[0];
42783
+ var y2 = array2[1];
42784
+ var xdiff = void 0;
42785
+ if (this._tabOrder === PdfFormFieldsTabOrder.row) {
42786
+ xdiff = this._compare(page1._pageIndex, page2._pageIndex);
42787
+ if (xdiff !== 0) {
42788
+ result = xdiff;
42789
+ }
42790
+ else {
42791
+ xdiff = this._compare(y2, y1);
42792
+ if (xdiff !== 0) {
42793
+ result = xdiff;
42794
+ }
42795
+ else {
42796
+ result = this._compare(x1, x2);
42797
+ }
42798
+ }
42799
+ }
42800
+ else if (this._tabOrder === PdfFormFieldsTabOrder.column) {
42801
+ xdiff = this._compare(page1._pageIndex, page2._pageIndex);
42802
+ if (xdiff !== 0) {
42803
+ result = xdiff;
42804
+ }
42805
+ else {
42806
+ xdiff = this._compare(x1, x2);
42807
+ if (xdiff !== 0) {
42808
+ result = xdiff;
42809
+ }
42810
+ else {
42811
+ result = this._compare(y2, y1);
42812
+ }
42813
+ }
42814
+ }
42815
+ }
42816
+ }
42817
+ return result;
42698
42818
  };
42699
42819
  PdfForm.prototype._clear = function () {
42700
42820
  this._fields = [];