@syncfusion/ej2-pdf 25.2.3 → 25.2.6

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.
@@ -41,6 +41,7 @@ var PdfField = /** @class */ (function () {
41
41
  function PdfField() {
42
42
  this._visible = true;
43
43
  this._isTransparentBackColor = false;
44
+ this._isTransparentBorderColor = false;
44
45
  this._defaultFont = new PdfStandardFont(PdfFontFamily.helvetica, 8);
45
46
  this._appearanceFont = new PdfStandardFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular);
46
47
  this._defaultItemFont = new PdfStandardFont(PdfFontFamily.timesRoman, 12);
@@ -660,29 +661,12 @@ var PdfField = /** @class */ (function () {
660
661
  * ```
661
662
  */
662
663
  get: function () {
663
- var value;
664
- var widget = this.itemAt(this._defaultIndex);
665
- if (widget && widget.borderColor) {
666
- value = widget.borderColor;
667
- }
668
- else if (this._mkDictionary) {
669
- var dictionary = this._mkDictionary;
670
- if (dictionary && dictionary.has('BC')) {
671
- var colorArray = dictionary.getArray('BC');
672
- if (colorArray) {
673
- value = _parseColor(colorArray);
674
- }
675
- }
676
- }
677
- if (typeof value === 'undefined' || value === null) {
678
- value = [0, 0, 0];
679
- }
680
- return value;
664
+ return this._parseBorderColor(true);
681
665
  },
682
666
  /**
683
667
  * Sets the border color of the field.
684
668
  *
685
- * @param {number[]} value R, G, B color values in between 0 to 255.
669
+ * @param {number[]} Value Array with R, G, B, A color values in between 0 to 255. For optional A (0-254), it signifies transparency.
686
670
  * ```typescript
687
671
  * // Load an existing PDF document
688
672
  * let document: PdfDocument = new PdfDocument(data, password);
@@ -697,26 +681,7 @@ var PdfField = /** @class */ (function () {
697
681
  * ```
698
682
  */
699
683
  set: function (value) {
700
- var widget = this.itemAt(this._defaultIndex);
701
- if (widget && widget.borderColor !== value) {
702
- widget.borderColor = value;
703
- }
704
- else {
705
- var mkDict = this._mkDictionary;
706
- if (typeof mkDict === 'undefined') {
707
- var dictionary = new _PdfDictionary(this._crossReference);
708
- dictionary.update('BC', [Number.parseFloat((value[0] / 255).toFixed(3)),
709
- Number.parseFloat((value[1] / 255).toFixed(3)),
710
- Number.parseFloat((value[2] / 255).toFixed(3))]);
711
- this._dictionary.update('MK', dictionary);
712
- }
713
- else if (!mkDict.has('BC') || _parseColor(mkDict.getArray('BC')) !== value) {
714
- mkDict.update('BC', [Number.parseFloat((value[0] / 255).toFixed(3)),
715
- Number.parseFloat((value[1] / 255).toFixed(3)),
716
- Number.parseFloat((value[2] / 255).toFixed(3))]);
717
- this._dictionary._updated = true;
718
- }
719
- }
684
+ this._updateBorderColor(value, true);
720
685
  },
721
686
  enumerable: true,
722
687
  configurable: true
@@ -1312,6 +1277,25 @@ var PdfField = /** @class */ (function () {
1312
1277
  enumerable: true,
1313
1278
  configurable: true
1314
1279
  });
1280
+ Object.defineProperty(PdfField.prototype, "_hasBorderColor", {
1281
+ get: function () {
1282
+ if (this._isLoaded) {
1283
+ var mkDictionary = this._mkDictionary;
1284
+ if (!mkDictionary) {
1285
+ var item = this.itemAt(this._defaultIndex);
1286
+ if (item && item._dictionary.has('MK')) {
1287
+ mkDictionary = item._dictionary.get('MK');
1288
+ }
1289
+ }
1290
+ return (mkDictionary && mkDictionary.has('BC'));
1291
+ }
1292
+ else {
1293
+ return !this._isTransparentBorderColor;
1294
+ }
1295
+ },
1296
+ enumerable: true,
1297
+ configurable: true
1298
+ });
1315
1299
  PdfField.prototype._parseBackColor = function (hasTransparency) {
1316
1300
  var value;
1317
1301
  if ((!hasTransparency) || ((this._isLoaded && this._hasBackColor) || (!this._isLoaded && !this._isTransparentBackColor))) {
@@ -1334,6 +1318,28 @@ var PdfField = /** @class */ (function () {
1334
1318
  }
1335
1319
  return value;
1336
1320
  };
1321
+ PdfField.prototype._parseBorderColor = function (hasTransparency) {
1322
+ var value;
1323
+ if ((!hasTransparency) || ((this._isLoaded && this._hasBorderColor) || (!this._isLoaded && !this._isTransparentBorderColor))) {
1324
+ var widget = this.itemAt(this._defaultIndex);
1325
+ if (widget && widget.borderColor) {
1326
+ value = widget.borderColor;
1327
+ }
1328
+ else if (this._mkDictionary) {
1329
+ var mkDict = this._mkDictionary;
1330
+ if (mkDict && mkDict.has('BC')) {
1331
+ var bgArray = mkDict.getArray('BC');
1332
+ if (bgArray) {
1333
+ value = _parseColor(bgArray);
1334
+ }
1335
+ }
1336
+ }
1337
+ if (typeof value === 'undefined' || value === null) {
1338
+ value = [0, 0, 0];
1339
+ }
1340
+ }
1341
+ return value;
1342
+ };
1337
1343
  PdfField.prototype._updateBackColor = function (value, hasTransparency) {
1338
1344
  if (hasTransparency === void 0) { hasTransparency = false; }
1339
1345
  if (hasTransparency && value.length === 4 && value[3] !== 255) {
@@ -1375,6 +1381,53 @@ var PdfField = /** @class */ (function () {
1375
1381
  }
1376
1382
  }
1377
1383
  };
1384
+ PdfField.prototype._updateBorderColor = function (value, hasTransparency) {
1385
+ if (hasTransparency === void 0) { hasTransparency = false; }
1386
+ if (hasTransparency && value.length === 4 && value[3] !== 255) {
1387
+ this._isTransparentBorderColor = true;
1388
+ if (this._dictionary.has('BC')) {
1389
+ delete this._dictionary._map.BC;
1390
+ }
1391
+ var mkDictionary = this._mkDictionary;
1392
+ if (mkDictionary && mkDictionary.has('BC')) {
1393
+ delete mkDictionary._map.BC;
1394
+ if (this._dictionary.has('BS')) {
1395
+ var bsDictionary = this._dictionary.get('BS');
1396
+ if (bsDictionary && bsDictionary.has('W')) {
1397
+ delete bsDictionary._map.W;
1398
+ }
1399
+ }
1400
+ this._dictionary._updated = true;
1401
+ }
1402
+ var item = this.itemAt(this._defaultIndex);
1403
+ if (item) {
1404
+ item.borderColor = value;
1405
+ }
1406
+ }
1407
+ else {
1408
+ this._isTransparentBorderColor = false;
1409
+ var widget = this.itemAt(this._defaultIndex);
1410
+ if (widget && widget.borderColor !== value) {
1411
+ widget.borderColor = value;
1412
+ }
1413
+ else {
1414
+ var mkDictionary = this._mkDictionary;
1415
+ if (typeof mkDictionary === 'undefined') {
1416
+ var dictionary = new _PdfDictionary(this._crossReference);
1417
+ dictionary.update('BC', [Number.parseFloat((value[0] / 255).toFixed(3)),
1418
+ Number.parseFloat((value[1] / 255).toFixed(3)),
1419
+ Number.parseFloat((value[2] / 255).toFixed(3))]);
1420
+ this._dictionary.update('MK', dictionary);
1421
+ }
1422
+ else if (!mkDictionary.has('BC') || _parseColor(mkDictionary.getArray('BC')) !== value) {
1423
+ mkDictionary.update('BC', [Number.parseFloat((value[0] / 255).toFixed(3)),
1424
+ Number.parseFloat((value[1] / 255).toFixed(3)),
1425
+ Number.parseFloat((value[2] / 255).toFixed(3))]);
1426
+ this._dictionary._updated = true;
1427
+ }
1428
+ }
1429
+ }
1430
+ };
1378
1431
  /**
1379
1432
  * Gets the field item as `PdfWidgetAnnotation` at the specified index.
1380
1433
  *
@@ -1846,19 +1899,19 @@ var PdfField = /** @class */ (function () {
1846
1899
  switch (state) {
1847
1900
  case _PdfCheckFieldState.unchecked:
1848
1901
  case _PdfCheckFieldState.checked:
1849
- if (parameter.borderPen) {
1902
+ if (parameter.borderPen || parameter.backBrush) {
1850
1903
  graphics.drawRectangle(parameter.bounds[0], parameter.bounds[1], parameter.bounds[2], parameter.bounds[3], parameter.backBrush);
1851
1904
  }
1852
1905
  break;
1853
1906
  case _PdfCheckFieldState.pressedChecked:
1854
1907
  case _PdfCheckFieldState.pressedUnchecked:
1855
- if ((parameter.borderStyle === PdfBorderStyle.beveled) ||
1908
+ if ((parameter.borderStyle === PdfBorderStyle.beveled || parameter.backBrush) ||
1856
1909
  (parameter.borderStyle === PdfBorderStyle.underline)) {
1857
- if (parameter.borderPen) {
1910
+ if (parameter.borderPen || parameter.backBrush) {
1858
1911
  graphics.drawRectangle(parameter.bounds[0], parameter.bounds[1], parameter.bounds[2], parameter.bounds[3], parameter.backBrush);
1859
1912
  }
1860
1913
  }
1861
- else if (parameter.borderPen) {
1914
+ else if (parameter.borderPen || parameter.shadowBrush) {
1862
1915
  graphics.drawRectangle(parameter.bounds[0], parameter.bounds[1], parameter.bounds[2], parameter.bounds[3], parameter.shadowBrush);
1863
1916
  }
1864
1917
  break;
@@ -3019,7 +3072,9 @@ var PdfTextBoxField = /** @class */ (function (_super) {
3019
3072
  }
3020
3073
  parameter.foreBrush = new PdfBrush(widget.color);
3021
3074
  var border = widget.border;
3022
- parameter.borderPen = new PdfPen(widget.borderColor, border.width);
3075
+ if (widget.borderColor) {
3076
+ parameter.borderPen = new PdfPen(widget.borderColor, border.width);
3077
+ }
3023
3078
  parameter.borderStyle = border.style;
3024
3079
  parameter.borderWidth = border.width;
3025
3080
  if (backcolor) {
@@ -3068,7 +3123,7 @@ var PdfTextBoxField = /** @class */ (function (_super) {
3068
3123
  if (typeof maxLength !== 'undefined') {
3069
3124
  if (parameter.insertSpaces) {
3070
3125
  var width = 0;
3071
- if (typeof maxLength !== 'undefined' && maxLength > 0) {
3126
+ if (typeof maxLength !== 'undefined' && maxLength > 0 && this.borderColor) {
3072
3127
  width = parameter.bounds[2] / maxLength;
3073
3128
  g.drawRectangle(parameter.bounds[0], parameter.bounds[1], parameter.bounds[2], parameter.bounds[3], parameter.borderPen, parameter.backBrush);
3074
3129
  var current = text;
@@ -3750,7 +3805,9 @@ var PdfButtonField = /** @class */ (function (_super) {
3750
3805
  }
3751
3806
  parameter.foreBrush = new PdfBrush(widget.color);
3752
3807
  var border = widget.border;
3753
- parameter.borderPen = new PdfPen(widget.borderColor, border.width);
3808
+ if (widget.borderColor) {
3809
+ parameter.borderPen = new PdfPen(widget.borderColor, border.width);
3810
+ }
3754
3811
  parameter.borderStyle = border.style;
3755
3812
  parameter.borderWidth = border.width;
3756
3813
  if (backcolor) {
@@ -4221,6 +4278,53 @@ var PdfCheckBoxField = /** @class */ (function (_super) {
4221
4278
  enumerable: true,
4222
4279
  configurable: true
4223
4280
  });
4281
+ Object.defineProperty(PdfCheckBoxField.prototype, "borderColor", {
4282
+ /**
4283
+ * Gets the border color of the field.
4284
+ *
4285
+ * @returns {number[]} R, G, B color values in between 0 to 255.
4286
+ * ```typescript
4287
+ * // Load an existing PDF document
4288
+ * let document: PdfDocument = new PdfDocument(data, password);
4289
+ * // Access the form field at index 0
4290
+ * let field: PdfField = document.form.fieldAt(0);
4291
+ * // Gets the border color of the field.
4292
+ * let borderColor: number[] = field.borderColor;
4293
+ * // Save the document
4294
+ * document.save('output.pdf');
4295
+ * // Destroy the document
4296
+ * document.destroy();
4297
+ * ```
4298
+ */
4299
+ get: function () {
4300
+ return this._parseBorderColor(true);
4301
+ },
4302
+ /**
4303
+ * Sets the border color of the field.
4304
+ *
4305
+ * @param {number[]} value Array with R, G, B, A color values in between 0 to 255. For optional A (0-254), it signifies transparency.
4306
+ * ```typescript
4307
+ * // Load an existing PDF document
4308
+ * let document: PdfDocument = new PdfDocument(data, password);
4309
+ * // Access the form field at index 0
4310
+ * let field: PdfField = document.form.fieldAt(0);
4311
+ * // Sets the border color of the field.
4312
+ * field.borderColor = [255, 0, 0];
4313
+ * // Save the document
4314
+ * document.save('output.pdf');
4315
+ * // Destroy the document
4316
+ * document.destroy();
4317
+ * ```
4318
+ */
4319
+ set: function (value) {
4320
+ this._updateBorderColor(value, true);
4321
+ if (this._isLoaded) {
4322
+ this._setAppearance = true;
4323
+ }
4324
+ },
4325
+ enumerable: true,
4326
+ configurable: true
4327
+ });
4224
4328
  PdfCheckBoxField.prototype._initialize = function (page, name, bounds) {
4225
4329
  this._crossReference = page._crossReference;
4226
4330
  this._page = page;
@@ -4313,7 +4417,9 @@ var PdfCheckBoxField = /** @class */ (function (_super) {
4313
4417
  }
4314
4418
  parameter.foreBrush = new PdfBrush(widget.color);
4315
4419
  var border = widget.border;
4316
- parameter.borderPen = new PdfPen(widget.borderColor, border.width);
4420
+ if (widget.borderColor) {
4421
+ parameter.borderPen = new PdfPen(widget.borderColor, border.width);
4422
+ }
4317
4423
  parameter.borderStyle = border.style;
4318
4424
  parameter.borderWidth = border.width;
4319
4425
  if (backcolor) {
@@ -4550,6 +4656,50 @@ var PdfRadioButtonListField = /** @class */ (function (_super) {
4550
4656
  enumerable: true,
4551
4657
  configurable: true
4552
4658
  });
4659
+ Object.defineProperty(PdfRadioButtonListField.prototype, "borderColor", {
4660
+ /**
4661
+ * Gets the border color of the field.
4662
+ *
4663
+ * @returns {number[]} R, G, B color values in between 0 to 255.
4664
+ * ```typescript
4665
+ * // Load an existing PDF document
4666
+ * let document: PdfDocument = new PdfDocument(data, password);
4667
+ * // Access the form field at index 0
4668
+ * let field: PdfField = document.form.fieldAt(0);
4669
+ * // Gets the border color of the field.
4670
+ * let borderColor: number[] = field.borderColor;
4671
+ * // Save the document
4672
+ * document.save('output.pdf');
4673
+ * // Destroy the document
4674
+ * document.destroy();
4675
+ * ```
4676
+ */
4677
+ get: function () {
4678
+ return this._parseBorderColor(!this._isLoaded);
4679
+ },
4680
+ /**
4681
+ * Sets the border color of the field.
4682
+ *
4683
+ * @param {number[]} value Array with R, G, B, A color values in between 0 to 255. For optional A (0-254), it signifies transparency.
4684
+ * ```typescript
4685
+ * // Load an existing PDF document
4686
+ * let document: PdfDocument = new PdfDocument(data, password);
4687
+ * // Access the form field at index 0
4688
+ * let field: PdfField = document.form.fieldAt(0);
4689
+ * // Sets the border color of the field.
4690
+ * field.borderColor = [255, 0, 0];
4691
+ * // Save the document
4692
+ * document.save('output.pdf');
4693
+ * // Destroy the document
4694
+ * document.destroy();
4695
+ * ```
4696
+ */
4697
+ set: function (value) {
4698
+ this._updateBorderColor(value, true);
4699
+ },
4700
+ enumerable: true,
4701
+ configurable: true
4702
+ });
4553
4703
  /**
4554
4704
  * Gets the item at the specified index.
4555
4705
  *
@@ -4805,7 +4955,9 @@ var PdfRadioButtonListField = /** @class */ (function (_super) {
4805
4955
  }
4806
4956
  parameter.foreBrush = new PdfBrush(widget.color);
4807
4957
  var border = widget.border;
4808
- parameter.borderPen = new PdfPen(widget.borderColor, border.width);
4958
+ if (widget.borderColor) {
4959
+ parameter.borderPen = new PdfPen(widget.borderColor, border.width);
4960
+ }
4809
4961
  parameter.borderStyle = border.style;
4810
4962
  parameter.borderWidth = border.width;
4811
4963
  if (backcolor) {
@@ -6222,7 +6374,9 @@ var PdfComboBoxField = /** @class */ (function (_super) {
6222
6374
  }
6223
6375
  parameter.foreBrush = new PdfBrush(item.color);
6224
6376
  var border = item.border;
6225
- parameter.borderPen = new PdfPen(item.borderColor, border.width);
6377
+ if (item.borderColor) {
6378
+ parameter.borderPen = new PdfPen(item.borderColor, border.width);
6379
+ }
6226
6380
  parameter.borderStyle = border.style;
6227
6381
  parameter.borderWidth = border.width;
6228
6382
  if (backcolor) {
@@ -6256,7 +6410,9 @@ var PdfComboBoxField = /** @class */ (function (_super) {
6256
6410
  }
6257
6411
  parameter.foreBrush = new PdfBrush(this.color);
6258
6412
  var border = this.border;
6259
- parameter.borderPen = new PdfPen(this.borderColor, border.width);
6413
+ if (this.borderColor) {
6414
+ parameter.borderPen = new PdfPen(this.borderColor, border.width);
6415
+ }
6260
6416
  parameter.borderStyle = border.style;
6261
6417
  parameter.borderWidth = border.width;
6262
6418
  if (backcolor) {
@@ -6609,7 +6765,9 @@ var PdfListBoxField = /** @class */ (function (_super) {
6609
6765
  }
6610
6766
  parameter.foreBrush = new PdfBrush(item.color);
6611
6767
  var border = item.border;
6612
- parameter.borderPen = new PdfPen(item.borderColor, border.width);
6768
+ if (item.borderColor) {
6769
+ parameter.borderPen = new PdfPen(item.borderColor, border.width);
6770
+ }
6613
6771
  parameter.borderStyle = border.style;
6614
6772
  parameter.borderWidth = border.width;
6615
6773
  if (backcolor) {
@@ -6641,7 +6799,9 @@ var PdfListBoxField = /** @class */ (function (_super) {
6641
6799
  }
6642
6800
  parameter.foreBrush = new PdfBrush(this.color);
6643
6801
  var border = this.border;
6644
- parameter.borderPen = new PdfPen(this.borderColor, border.width);
6802
+ if (this.borderColor) {
6803
+ parameter.borderPen = new PdfPen(this.borderColor, border.width);
6804
+ }
6645
6805
  parameter.borderStyle = border.style;
6646
6806
  parameter.borderWidth = border.width;
6647
6807
  if (backcolor) {
@@ -6952,7 +7112,7 @@ var PdfSignatureField = /** @class */ (function (_super) {
6952
7112
  PdfSignatureField.prototype._doPostProcess = function (isFlatten) {
6953
7113
  if (isFlatten === void 0) { isFlatten = false; }
6954
7114
  var needAppearance = this._setAppearance || this._form._setAppearance;
6955
- if (!this._isLoaded && (isFlatten || needAppearance)) {
7115
+ if (isFlatten || needAppearance) {
6956
7116
  var count = this._kidsCount;
6957
7117
  if (count > 0) {
6958
7118
  for (var i = 0; i < count; i++) {
@@ -7000,7 +7160,9 @@ var PdfSignatureField = /** @class */ (function (_super) {
7000
7160
  }
7001
7161
  parameter.foreBrush = new PdfBrush(widget.color);
7002
7162
  var border = widget.border;
7003
- parameter.borderPen = new PdfPen(widget.borderColor, border.width);
7163
+ if (widget.borderColor) {
7164
+ parameter.borderPen = new PdfPen(widget.borderColor, border.width);
7165
+ }
7004
7166
  parameter.borderStyle = border.style;
7005
7167
  parameter.borderWidth = border.width;
7006
7168
  if (backcolor) {