@syncfusion/ej2-pdf 24.1.47 → 24.2.3
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.
- package/CHANGELOG.md +8 -0
- package/dist/ej2-pdf.umd.min.js +2 -2
- package/dist/ej2-pdf.umd.min.js.map +1 -1
- package/dist/es6/ej2-pdf.es2015.js +548 -167
- package/dist/es6/ej2-pdf.es2015.js.map +1 -1
- package/dist/es6/ej2-pdf.es5.js +582 -167
- package/dist/es6/ej2-pdf.es5.js.map +1 -1
- package/dist/global/ej2-pdf.min.js +2 -2
- package/dist/global/ej2-pdf.min.js.map +1 -1
- package/dist/global/index.d.ts +1 -1
- package/package.json +7 -7
- package/src/pdf/core/annotations/annotation.d.ts +57 -14
- package/src/pdf/core/annotations/annotation.js +129 -34
- package/src/pdf/core/form/field.d.ts +203 -5
- package/src/pdf/core/form/field.js +453 -133
|
@@ -6933,6 +6933,7 @@ var _PathPointType;
|
|
|
6933
6933
|
class PdfField {
|
|
6934
6934
|
constructor() {
|
|
6935
6935
|
this._visible = true;
|
|
6936
|
+
this._isTransparentBackColor = false;
|
|
6936
6937
|
this._defaultFont = new PdfStandardFont(PdfFontFamily.helvetica, 8);
|
|
6937
6938
|
this._appearanceFont = new PdfStandardFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular);
|
|
6938
6939
|
this._defaultItemFont = new PdfStandardFont(PdfFontFamily.timesRoman, 12);
|
|
@@ -7450,7 +7451,7 @@ class PdfField {
|
|
|
7450
7451
|
}
|
|
7451
7452
|
}
|
|
7452
7453
|
/**
|
|
7453
|
-
* Gets the
|
|
7454
|
+
* Gets the background color of the field.
|
|
7454
7455
|
*
|
|
7455
7456
|
* @returns {number[]} R, G, B color values in between 0 to 255.
|
|
7456
7457
|
* ```typescript
|
|
@@ -7458,7 +7459,7 @@ class PdfField {
|
|
|
7458
7459
|
* let document: PdfDocument = new PdfDocument(data, password);
|
|
7459
7460
|
* // Access the form field at index 0
|
|
7460
7461
|
* let field: PdfField = document.form.fieldAt(0);
|
|
7461
|
-
* // Gets the
|
|
7462
|
+
* // Gets the background color of the field.
|
|
7462
7463
|
* let backColor: number[] = field.backColor;
|
|
7463
7464
|
* // Save the document
|
|
7464
7465
|
* document.save('output.pdf');
|
|
@@ -7467,27 +7468,10 @@ class PdfField {
|
|
|
7467
7468
|
* ```
|
|
7468
7469
|
*/
|
|
7469
7470
|
get backColor() {
|
|
7470
|
-
|
|
7471
|
-
const widget = this.itemAt(this._defaultIndex);
|
|
7472
|
-
if (widget && widget.backColor) {
|
|
7473
|
-
value = widget.backColor;
|
|
7474
|
-
}
|
|
7475
|
-
else if (this._mkDictionary) {
|
|
7476
|
-
const mkDict = this._mkDictionary;
|
|
7477
|
-
if (mkDict && mkDict.has('BG')) {
|
|
7478
|
-
const bgArray = mkDict.getArray('BG');
|
|
7479
|
-
if (bgArray) {
|
|
7480
|
-
value = _parseColor(bgArray);
|
|
7481
|
-
}
|
|
7482
|
-
}
|
|
7483
|
-
}
|
|
7484
|
-
if (typeof value === 'undefined' || value === null) {
|
|
7485
|
-
value = [255, 255, 255];
|
|
7486
|
-
}
|
|
7487
|
-
return value;
|
|
7471
|
+
return this._parseBackColor(false);
|
|
7488
7472
|
}
|
|
7489
7473
|
/**
|
|
7490
|
-
* Sets the
|
|
7474
|
+
* Sets the background color of the field.
|
|
7491
7475
|
*
|
|
7492
7476
|
* @param {number[]} value R, G, B color values in between 0 to 255.
|
|
7493
7477
|
* ```typescript
|
|
@@ -7495,7 +7479,7 @@ class PdfField {
|
|
|
7495
7479
|
* let document: PdfDocument = new PdfDocument(data, password);
|
|
7496
7480
|
* // Access the form field at index 0
|
|
7497
7481
|
* let field: PdfField = document.form.fieldAt(0);
|
|
7498
|
-
* // Sets the
|
|
7482
|
+
* // Sets the background color of the field.
|
|
7499
7483
|
* field.backColor = [255, 0, 0];
|
|
7500
7484
|
* // Save the document
|
|
7501
7485
|
* document.save('output.pdf');
|
|
@@ -7504,27 +7488,7 @@ class PdfField {
|
|
|
7504
7488
|
* ```
|
|
7505
7489
|
*/
|
|
7506
7490
|
set backColor(value) {
|
|
7507
|
-
|
|
7508
|
-
if (widget && widget.backColor !== value) {
|
|
7509
|
-
widget.backColor = value;
|
|
7510
|
-
}
|
|
7511
|
-
else {
|
|
7512
|
-
const mkDictionary = this._mkDictionary;
|
|
7513
|
-
if (typeof mkDictionary === 'undefined') {
|
|
7514
|
-
const dictionary = new _PdfDictionary(this._crossReference);
|
|
7515
|
-
dictionary.update('BG', [Number.parseFloat((value[0] / 255).toFixed(3)),
|
|
7516
|
-
Number.parseFloat((value[1] / 255).toFixed(3)),
|
|
7517
|
-
Number.parseFloat((value[2] / 255).toFixed(3))]);
|
|
7518
|
-
this._dictionary.update('MK', dictionary);
|
|
7519
|
-
}
|
|
7520
|
-
else if (!mkDictionary.has('BG') || _parseColor(mkDictionary.getArray('BG')) !== value) {
|
|
7521
|
-
mkDictionary.update('BG', [Number.parseFloat((value[0] / 255).toFixed(3)),
|
|
7522
|
-
Number.parseFloat((value[1] / 255).toFixed(3)),
|
|
7523
|
-
Number.parseFloat((value[2] / 255).toFixed(3))]);
|
|
7524
|
-
this._dictionary._updated = true;
|
|
7525
|
-
}
|
|
7526
|
-
}
|
|
7527
|
-
this._backColorSet = true;
|
|
7491
|
+
this._updateBackColor(value);
|
|
7528
7492
|
}
|
|
7529
7493
|
/**
|
|
7530
7494
|
* Gets the border color of the field.
|
|
@@ -8118,6 +8082,83 @@ class PdfField {
|
|
|
8118
8082
|
get _kidsCount() {
|
|
8119
8083
|
return this._kids ? this._kids.length : 0;
|
|
8120
8084
|
}
|
|
8085
|
+
get _hasBackColor() {
|
|
8086
|
+
if (this._isLoaded) {
|
|
8087
|
+
let mkDictionary = this._mkDictionary;
|
|
8088
|
+
if (!mkDictionary) {
|
|
8089
|
+
const item = this.itemAt(this._defaultIndex);
|
|
8090
|
+
if (item && item._dictionary.has('MK')) {
|
|
8091
|
+
mkDictionary = item._dictionary.get('MK');
|
|
8092
|
+
}
|
|
8093
|
+
}
|
|
8094
|
+
return (mkDictionary && mkDictionary.has('BG'));
|
|
8095
|
+
}
|
|
8096
|
+
else {
|
|
8097
|
+
return !this._isTransparentBackColor;
|
|
8098
|
+
}
|
|
8099
|
+
}
|
|
8100
|
+
_parseBackColor(hasTransparency) {
|
|
8101
|
+
let value;
|
|
8102
|
+
if ((!hasTransparency) || ((this._isLoaded && this._hasBackColor) || (!this._isLoaded && !this._isTransparentBackColor))) {
|
|
8103
|
+
const widget = this.itemAt(this._defaultIndex);
|
|
8104
|
+
if (widget && widget.backColor) {
|
|
8105
|
+
value = widget.backColor;
|
|
8106
|
+
}
|
|
8107
|
+
else if (this._mkDictionary) {
|
|
8108
|
+
const mkDict = this._mkDictionary;
|
|
8109
|
+
if (mkDict && mkDict.has('BG')) {
|
|
8110
|
+
const bgArray = mkDict.getArray('BG');
|
|
8111
|
+
if (bgArray) {
|
|
8112
|
+
value = _parseColor(bgArray);
|
|
8113
|
+
}
|
|
8114
|
+
}
|
|
8115
|
+
}
|
|
8116
|
+
if (typeof value === 'undefined' || value === null) {
|
|
8117
|
+
value = [255, 255, 255];
|
|
8118
|
+
}
|
|
8119
|
+
}
|
|
8120
|
+
return value;
|
|
8121
|
+
}
|
|
8122
|
+
_updateBackColor(value, hasTransparency = false) {
|
|
8123
|
+
if (hasTransparency && value.length === 4 && value[3] !== 255) {
|
|
8124
|
+
this._isTransparentBackColor = true;
|
|
8125
|
+
if (this._dictionary.has('BG')) {
|
|
8126
|
+
delete this._dictionary._map.BG;
|
|
8127
|
+
}
|
|
8128
|
+
const mkDictionary = this._mkDictionary;
|
|
8129
|
+
if (mkDictionary && mkDictionary.has('BG')) {
|
|
8130
|
+
delete mkDictionary._map.BG;
|
|
8131
|
+
this._dictionary._updated = true;
|
|
8132
|
+
}
|
|
8133
|
+
const item = this.itemAt(this._defaultIndex);
|
|
8134
|
+
if (item) {
|
|
8135
|
+
item.backColor = value;
|
|
8136
|
+
}
|
|
8137
|
+
}
|
|
8138
|
+
else {
|
|
8139
|
+
this._isTransparentBackColor = false;
|
|
8140
|
+
const widget = this.itemAt(this._defaultIndex);
|
|
8141
|
+
if (widget && widget.backColor !== value) {
|
|
8142
|
+
widget.backColor = value;
|
|
8143
|
+
}
|
|
8144
|
+
else {
|
|
8145
|
+
const mkDictionary = this._mkDictionary;
|
|
8146
|
+
if (typeof mkDictionary === 'undefined') {
|
|
8147
|
+
const dictionary = new _PdfDictionary(this._crossReference);
|
|
8148
|
+
dictionary.update('BG', [Number.parseFloat((value[0] / 255).toFixed(3)),
|
|
8149
|
+
Number.parseFloat((value[1] / 255).toFixed(3)),
|
|
8150
|
+
Number.parseFloat((value[2] / 255).toFixed(3))]);
|
|
8151
|
+
this._dictionary.update('MK', dictionary);
|
|
8152
|
+
}
|
|
8153
|
+
else if (!mkDictionary.has('BG') || _parseColor(mkDictionary.getArray('BG')) !== value) {
|
|
8154
|
+
mkDictionary.update('BG', [Number.parseFloat((value[0] / 255).toFixed(3)),
|
|
8155
|
+
Number.parseFloat((value[1] / 255).toFixed(3)),
|
|
8156
|
+
Number.parseFloat((value[2] / 255).toFixed(3))]);
|
|
8157
|
+
this._dictionary._updated = true;
|
|
8158
|
+
}
|
|
8159
|
+
}
|
|
8160
|
+
}
|
|
8161
|
+
}
|
|
8121
8162
|
/**
|
|
8122
8163
|
* Gets the field item as `PdfWidgetAnnotation` at the specified index.
|
|
8123
8164
|
*
|
|
@@ -8533,42 +8574,44 @@ class PdfField {
|
|
|
8533
8574
|
const width = parameter.bounds[2] + (2 * inflateValue);
|
|
8534
8575
|
const height = parameter.bounds[3] + (2 * inflateValue);
|
|
8535
8576
|
const shadowBrush = parameter.shadowBrush;
|
|
8536
|
-
|
|
8537
|
-
|
|
8538
|
-
|
|
8539
|
-
|
|
8540
|
-
|
|
8541
|
-
|
|
8542
|
-
|
|
8543
|
-
|
|
8544
|
-
|
|
8545
|
-
|
|
8546
|
-
|
|
8547
|
-
|
|
8548
|
-
|
|
8549
|
-
|
|
8550
|
-
|
|
8551
|
-
|
|
8552
|
-
|
|
8553
|
-
|
|
8554
|
-
|
|
8555
|
-
|
|
8556
|
-
|
|
8557
|
-
|
|
8558
|
-
|
|
8559
|
-
|
|
8560
|
-
|
|
8561
|
-
|
|
8562
|
-
|
|
8563
|
-
|
|
8564
|
-
|
|
8565
|
-
|
|
8566
|
-
|
|
8567
|
-
|
|
8568
|
-
|
|
8569
|
-
|
|
8570
|
-
|
|
8571
|
-
|
|
8577
|
+
if (shadowBrush) {
|
|
8578
|
+
const shadowColor = shadowBrush._color;
|
|
8579
|
+
let leftTop;
|
|
8580
|
+
let rightBottom;
|
|
8581
|
+
switch (parameter.borderStyle) {
|
|
8582
|
+
case PdfBorderStyle.beveled:
|
|
8583
|
+
switch (state) {
|
|
8584
|
+
case _PdfCheckFieldState.pressedChecked:
|
|
8585
|
+
case _PdfCheckFieldState.pressedUnchecked:
|
|
8586
|
+
leftTop = new PdfPen(shadowColor, borderWidth);
|
|
8587
|
+
rightBottom = new PdfPen([255, 255, 255], borderWidth);
|
|
8588
|
+
break;
|
|
8589
|
+
case _PdfCheckFieldState.checked:
|
|
8590
|
+
case _PdfCheckFieldState.unchecked:
|
|
8591
|
+
leftTop = new PdfPen([255, 255, 255], borderWidth);
|
|
8592
|
+
rightBottom = new PdfPen(shadowColor, borderWidth);
|
|
8593
|
+
break;
|
|
8594
|
+
}
|
|
8595
|
+
break;
|
|
8596
|
+
case PdfBorderStyle.inset:
|
|
8597
|
+
switch (state) {
|
|
8598
|
+
case _PdfCheckFieldState.pressedChecked:
|
|
8599
|
+
case _PdfCheckFieldState.pressedUnchecked:
|
|
8600
|
+
leftTop = new PdfPen([0, 0, 0], borderWidth);
|
|
8601
|
+
rightBottom = new PdfPen([0, 0, 0], borderWidth);
|
|
8602
|
+
break;
|
|
8603
|
+
case _PdfCheckFieldState.checked:
|
|
8604
|
+
case _PdfCheckFieldState.unchecked:
|
|
8605
|
+
leftTop = new PdfPen([128, 128, 128], borderWidth);
|
|
8606
|
+
rightBottom = new PdfPen([192, 192, 192], borderWidth);
|
|
8607
|
+
break;
|
|
8608
|
+
}
|
|
8609
|
+
break;
|
|
8610
|
+
}
|
|
8611
|
+
if (leftTop && rightBottom) {
|
|
8612
|
+
graphics.drawArc(x, y, width, height, 135, 180, leftTop);
|
|
8613
|
+
graphics.drawArc(x, y, width, height, -45, 180, rightBottom);
|
|
8614
|
+
}
|
|
8572
8615
|
}
|
|
8573
8616
|
}
|
|
8574
8617
|
_drawCheckBox(graphics, parameter, checkSymbol, state, font) {
|
|
@@ -9507,6 +9550,50 @@ class PdfTextBoxField extends PdfField {
|
|
|
9507
9550
|
this._initializeFont(value);
|
|
9508
9551
|
}
|
|
9509
9552
|
}
|
|
9553
|
+
/**
|
|
9554
|
+
* Gets the background color of the field.
|
|
9555
|
+
*
|
|
9556
|
+
* @returns {number[]} R, G, B color values in between 0 to 255.
|
|
9557
|
+
* ```typescript
|
|
9558
|
+
* // Load an existing PDF document
|
|
9559
|
+
* let document: PdfDocument = new PdfDocument(data, password);
|
|
9560
|
+
* // Access the form field at index 0
|
|
9561
|
+
* let field: PdfField = document.form.fieldAt(0);
|
|
9562
|
+
* // Gets the background color of the field.
|
|
9563
|
+
* let backColor: number[] = field.backColor;
|
|
9564
|
+
* // Save the document
|
|
9565
|
+
* document.save('output.pdf');
|
|
9566
|
+
* // Destroy the document
|
|
9567
|
+
* document.destroy();
|
|
9568
|
+
* ```
|
|
9569
|
+
*/
|
|
9570
|
+
get backColor() {
|
|
9571
|
+
return this._parseBackColor(true);
|
|
9572
|
+
}
|
|
9573
|
+
/**
|
|
9574
|
+
* Sets the background color of the field.
|
|
9575
|
+
*
|
|
9576
|
+
* @param {number[]} value Array with R, G, B, A color values in between 0 to 255. For optional A (0-254), it signifies transparency.
|
|
9577
|
+
* ```typescript
|
|
9578
|
+
* // Load an existing PDF document
|
|
9579
|
+
* let document: PdfDocument = new PdfDocument(data, password);
|
|
9580
|
+
* // Access the text box field at index 0
|
|
9581
|
+
* let firstName: PdfField = document.form.fieldAt(0);
|
|
9582
|
+
* // Sets the background color of the field.
|
|
9583
|
+
* firstName.backColor = [255, 0, 0];
|
|
9584
|
+
* // Access the text box field at index 1
|
|
9585
|
+
* let secondName: PdfField = document.form.fieldAt(1);
|
|
9586
|
+
* // Sets the background color of the field to transparent.
|
|
9587
|
+
* secondName.backColor = [0, 0, 0, 0];
|
|
9588
|
+
* // Save the document
|
|
9589
|
+
* document.save('output.pdf');
|
|
9590
|
+
* // Destroy the document
|
|
9591
|
+
* document.destroy();
|
|
9592
|
+
* ```
|
|
9593
|
+
*/
|
|
9594
|
+
set backColor(value) {
|
|
9595
|
+
this._updateBackColor(value, true);
|
|
9596
|
+
}
|
|
9510
9597
|
_initialize(page, name, bounds) {
|
|
9511
9598
|
this._crossReference = page._crossReference;
|
|
9512
9599
|
this._page = page;
|
|
@@ -9635,7 +9722,7 @@ class PdfTextBoxField extends PdfField {
|
|
|
9635
9722
|
const parameter = new _PaintParameter();
|
|
9636
9723
|
parameter.bounds = [0, 0, bounds.width, bounds.height];
|
|
9637
9724
|
const backcolor = widget.backColor;
|
|
9638
|
-
if (isFlatten) {
|
|
9725
|
+
if (isFlatten && backcolor) {
|
|
9639
9726
|
parameter.backBrush = new PdfBrush(backcolor);
|
|
9640
9727
|
}
|
|
9641
9728
|
parameter.foreBrush = new PdfBrush(widget.color);
|
|
@@ -9643,11 +9730,13 @@ class PdfTextBoxField extends PdfField {
|
|
|
9643
9730
|
parameter.borderPen = new PdfPen(widget.borderColor, border.width);
|
|
9644
9731
|
parameter.borderStyle = border.style;
|
|
9645
9732
|
parameter.borderWidth = border.width;
|
|
9646
|
-
|
|
9647
|
-
|
|
9648
|
-
shadowColor[
|
|
9649
|
-
|
|
9650
|
-
|
|
9733
|
+
if (backcolor) {
|
|
9734
|
+
const shadowColor = [backcolor[0] - 64, backcolor[1] - 64, backcolor[2] - 64];
|
|
9735
|
+
const color = [shadowColor[0] >= 0 ? shadowColor[0] : 0,
|
|
9736
|
+
shadowColor[1] >= 0 ? shadowColor[1] : 0,
|
|
9737
|
+
shadowColor[2] >= 0 ? shadowColor[2] : 0];
|
|
9738
|
+
parameter.shadowBrush = new PdfBrush(color);
|
|
9739
|
+
}
|
|
9651
9740
|
parameter.rotationAngle = widget.rotate;
|
|
9652
9741
|
parameter.insertSpaces = this.insertSpaces;
|
|
9653
9742
|
let text = this.text;
|
|
@@ -10109,6 +10198,50 @@ class PdfButtonField extends PdfField {
|
|
|
10109
10198
|
this._initializeFont(value);
|
|
10110
10199
|
}
|
|
10111
10200
|
}
|
|
10201
|
+
/**
|
|
10202
|
+
* Gets the background color of the field.
|
|
10203
|
+
*
|
|
10204
|
+
* @returns {number[]} R, G, B color values in between 0 to 255.
|
|
10205
|
+
* ```typescript
|
|
10206
|
+
* // Load an existing PDF document
|
|
10207
|
+
* let document: PdfDocument = new PdfDocument(data, password);
|
|
10208
|
+
* // Access the form field at index 0
|
|
10209
|
+
* let field: PdfField = document.form.fieldAt(0);
|
|
10210
|
+
* // Gets the background color of the field.
|
|
10211
|
+
* let backColor: number[] = field.backColor;
|
|
10212
|
+
* // Save the document
|
|
10213
|
+
* document.save('output.pdf');
|
|
10214
|
+
* // Destroy the document
|
|
10215
|
+
* document.destroy();
|
|
10216
|
+
* ```
|
|
10217
|
+
*/
|
|
10218
|
+
get backColor() {
|
|
10219
|
+
return this._parseBackColor(true);
|
|
10220
|
+
}
|
|
10221
|
+
/**
|
|
10222
|
+
* Sets the background color of the field.
|
|
10223
|
+
*
|
|
10224
|
+
* @param {number[]} value Array with R, G, B, A color values in between 0 to 255. For optional A (0-254), it signifies transparency.
|
|
10225
|
+
* ```typescript
|
|
10226
|
+
* // Load an existing PDF document
|
|
10227
|
+
* let document: PdfDocument = new PdfDocument(data, password);
|
|
10228
|
+
* // Access the button field at index 0
|
|
10229
|
+
* let submitButton: PdfField = document.form.fieldAt(0);
|
|
10230
|
+
* // Sets the background color of the field.
|
|
10231
|
+
* submitButton.backColor = [255, 0, 0];
|
|
10232
|
+
* // Access the button field at index 1
|
|
10233
|
+
* let cancelButton: PdfField = document.form.fieldAt(1);
|
|
10234
|
+
* // Sets the background color of the field to transparent.
|
|
10235
|
+
* cancelButton.backColor = [0, 0, 0, 0];
|
|
10236
|
+
* // Save the document
|
|
10237
|
+
* document.save('output.pdf');
|
|
10238
|
+
* // Destroy the document
|
|
10239
|
+
* document.destroy();
|
|
10240
|
+
* ```
|
|
10241
|
+
*/
|
|
10242
|
+
set backColor(value) {
|
|
10243
|
+
this._updateBackColor(value, true);
|
|
10244
|
+
}
|
|
10112
10245
|
_assignText(fieldDictionary, value) {
|
|
10113
10246
|
let dictionary;
|
|
10114
10247
|
if (fieldDictionary.has('MK')) {
|
|
@@ -10267,17 +10400,21 @@ class PdfButtonField extends PdfField {
|
|
|
10267
10400
|
const parameter = new _PaintParameter();
|
|
10268
10401
|
parameter.bounds = [0, 0, bounds.width, bounds.height];
|
|
10269
10402
|
const backcolor = widget.backColor;
|
|
10270
|
-
|
|
10403
|
+
if (backcolor) {
|
|
10404
|
+
parameter.backBrush = new PdfBrush(backcolor);
|
|
10405
|
+
}
|
|
10271
10406
|
parameter.foreBrush = new PdfBrush(widget.color);
|
|
10272
10407
|
const border = widget.border;
|
|
10273
10408
|
parameter.borderPen = new PdfPen(widget.borderColor, border.width);
|
|
10274
10409
|
parameter.borderStyle = border.style;
|
|
10275
10410
|
parameter.borderWidth = border.width;
|
|
10276
|
-
|
|
10277
|
-
|
|
10278
|
-
shadowColor[
|
|
10279
|
-
|
|
10280
|
-
|
|
10411
|
+
if (backcolor) {
|
|
10412
|
+
const shadowColor = [backcolor[0] - 64, backcolor[1] - 64, backcolor[2] - 64];
|
|
10413
|
+
const color = [shadowColor[0] >= 0 ? shadowColor[0] : 0,
|
|
10414
|
+
shadowColor[1] >= 0 ? shadowColor[1] : 0,
|
|
10415
|
+
shadowColor[2] >= 0 ? shadowColor[2] : 0];
|
|
10416
|
+
parameter.shadowBrush = new PdfBrush(color);
|
|
10417
|
+
}
|
|
10281
10418
|
parameter.rotationAngle = widget.rotate;
|
|
10282
10419
|
if (typeof this._font === 'undefined' || this._font === null) {
|
|
10283
10420
|
this._font = this._defaultFont;
|
|
@@ -10675,6 +10812,50 @@ class PdfCheckBoxField extends PdfField {
|
|
|
10675
10812
|
this._setTextAlignment(value);
|
|
10676
10813
|
}
|
|
10677
10814
|
}
|
|
10815
|
+
/**
|
|
10816
|
+
* Gets the background color of the field.
|
|
10817
|
+
*
|
|
10818
|
+
* @returns {number[]} R, G, B color values in between 0 to 255.
|
|
10819
|
+
* ```typescript
|
|
10820
|
+
* // Load an existing PDF document
|
|
10821
|
+
* let document: PdfDocument = new PdfDocument(data, password);
|
|
10822
|
+
* // Access the form field at index 0
|
|
10823
|
+
* let field: PdfField = document.form.fieldAt(0);
|
|
10824
|
+
* // Gets the background color of the field.
|
|
10825
|
+
* let backColor: number[] = field.backColor;
|
|
10826
|
+
* // Save the document
|
|
10827
|
+
* document.save('output.pdf');
|
|
10828
|
+
* // Destroy the document
|
|
10829
|
+
* document.destroy();
|
|
10830
|
+
* ```
|
|
10831
|
+
*/
|
|
10832
|
+
get backColor() {
|
|
10833
|
+
return this._parseBackColor(true);
|
|
10834
|
+
}
|
|
10835
|
+
/**
|
|
10836
|
+
* Sets the background color of the field.
|
|
10837
|
+
*
|
|
10838
|
+
* @param {number[]} value Array with R, G, B, A color values in between 0 to 255. For optional A (0-254), it signifies transparency.
|
|
10839
|
+
* ```typescript
|
|
10840
|
+
* // Load an existing PDF document
|
|
10841
|
+
* let document: PdfDocument = new PdfDocument(data, password);
|
|
10842
|
+
* // Access the check box field at index 0
|
|
10843
|
+
* let checkBox1: PdfField = document.form.fieldAt(0);
|
|
10844
|
+
* // Sets the background color of the field.
|
|
10845
|
+
* checkBox1.backColor = [255, 0, 0];
|
|
10846
|
+
* // Access the check box field at index 1
|
|
10847
|
+
* let checkBox2: PdfField = document.form.fieldAt(1);
|
|
10848
|
+
* // Sets the background color of the field to transparent.
|
|
10849
|
+
* checkBox2.backColor = [0, 0, 0, 0];
|
|
10850
|
+
* // Save the document
|
|
10851
|
+
* document.save('output.pdf');
|
|
10852
|
+
* // Destroy the document
|
|
10853
|
+
* document.destroy();
|
|
10854
|
+
* ```
|
|
10855
|
+
*/
|
|
10856
|
+
set backColor(value) {
|
|
10857
|
+
this._updateBackColor(value, true);
|
|
10858
|
+
}
|
|
10678
10859
|
_initialize(page, name, bounds) {
|
|
10679
10860
|
this._crossReference = page._crossReference;
|
|
10680
10861
|
this._page = page;
|
|
@@ -10761,17 +10942,21 @@ class PdfCheckBoxField extends PdfField {
|
|
|
10761
10942
|
const parameter = new _PaintParameter();
|
|
10762
10943
|
parameter.bounds = [0, 0, bounds.width, bounds.height];
|
|
10763
10944
|
const backcolor = widget.backColor;
|
|
10764
|
-
|
|
10945
|
+
if (backcolor) {
|
|
10946
|
+
parameter.backBrush = new PdfBrush(backcolor);
|
|
10947
|
+
}
|
|
10765
10948
|
parameter.foreBrush = new PdfBrush(widget.color);
|
|
10766
10949
|
const border = widget.border;
|
|
10767
10950
|
parameter.borderPen = new PdfPen(widget.borderColor, border.width);
|
|
10768
10951
|
parameter.borderStyle = border.style;
|
|
10769
10952
|
parameter.borderWidth = border.width;
|
|
10770
|
-
|
|
10771
|
-
|
|
10772
|
-
shadowColor[
|
|
10773
|
-
|
|
10774
|
-
|
|
10953
|
+
if (backcolor) {
|
|
10954
|
+
const shadowColor = [backcolor[0] - 64, backcolor[1] - 64, backcolor[2] - 64];
|
|
10955
|
+
const color = [shadowColor[0] >= 0 ? shadowColor[0] : 0,
|
|
10956
|
+
shadowColor[1] >= 0 ? shadowColor[1] : 0,
|
|
10957
|
+
shadowColor[2] >= 0 ? shadowColor[2] : 0];
|
|
10958
|
+
parameter.shadowBrush = new PdfBrush(color);
|
|
10959
|
+
}
|
|
10775
10960
|
parameter.rotationAngle = widget.rotate;
|
|
10776
10961
|
const template = new PdfTemplate(parameter.bounds, this._crossReference);
|
|
10777
10962
|
const graphics = template.graphics;
|
|
@@ -11236,17 +11421,21 @@ class PdfRadioButtonListField extends PdfField {
|
|
|
11236
11421
|
const parameter = new _PaintParameter();
|
|
11237
11422
|
parameter.bounds = [0, 0, bounds.width, bounds.height];
|
|
11238
11423
|
const backcolor = widget.backColor;
|
|
11239
|
-
|
|
11424
|
+
if (backcolor) {
|
|
11425
|
+
parameter.backBrush = new PdfBrush(backcolor);
|
|
11426
|
+
}
|
|
11240
11427
|
parameter.foreBrush = new PdfBrush(widget.color);
|
|
11241
11428
|
const border = widget.border;
|
|
11242
11429
|
parameter.borderPen = new PdfPen(widget.borderColor, border.width);
|
|
11243
11430
|
parameter.borderStyle = border.style;
|
|
11244
11431
|
parameter.borderWidth = border.width;
|
|
11245
|
-
|
|
11246
|
-
|
|
11247
|
-
shadowColor[
|
|
11248
|
-
|
|
11249
|
-
|
|
11432
|
+
if (backcolor) {
|
|
11433
|
+
const shadowColor = [backcolor[0] - 64, backcolor[1] - 64, backcolor[2] - 64];
|
|
11434
|
+
const color = [shadowColor[0] >= 0 ? shadowColor[0] : 0,
|
|
11435
|
+
shadowColor[1] >= 0 ? shadowColor[1] : 0,
|
|
11436
|
+
shadowColor[2] >= 0 ? shadowColor[2] : 0];
|
|
11437
|
+
parameter.shadowBrush = new PdfBrush(color);
|
|
11438
|
+
}
|
|
11250
11439
|
parameter.rotationAngle = widget.rotate;
|
|
11251
11440
|
const template = new PdfTemplate(parameter.bounds, this._crossReference);
|
|
11252
11441
|
const graphics = template.graphics;
|
|
@@ -11929,6 +12118,50 @@ class PdfListField extends PdfField {
|
|
|
11929
12118
|
this._setTextAlignment(value);
|
|
11930
12119
|
}
|
|
11931
12120
|
}
|
|
12121
|
+
/**
|
|
12122
|
+
* Gets the background color of the field.
|
|
12123
|
+
*
|
|
12124
|
+
* @returns {number[]} R, G, B color values in between 0 to 255.
|
|
12125
|
+
* ```typescript
|
|
12126
|
+
* // Load an existing PDF document
|
|
12127
|
+
* let document: PdfDocument = new PdfDocument(data, password);
|
|
12128
|
+
* // Access the form field at index 0
|
|
12129
|
+
* let field: PdfField = document.form.fieldAt(0);
|
|
12130
|
+
* // Gets the background color of the field.
|
|
12131
|
+
* let backColor: number[] = field.backColor;
|
|
12132
|
+
* // Save the document
|
|
12133
|
+
* document.save('output.pdf');
|
|
12134
|
+
* // Destroy the document
|
|
12135
|
+
* document.destroy();
|
|
12136
|
+
* ```
|
|
12137
|
+
*/
|
|
12138
|
+
get backColor() {
|
|
12139
|
+
return this._parseBackColor(true);
|
|
12140
|
+
}
|
|
12141
|
+
/**
|
|
12142
|
+
* Sets the background color of the field.
|
|
12143
|
+
*
|
|
12144
|
+
* @param {number[]} value Array with R, G, B, A color values in between 0 to 255. For optional A (0-254), it signifies transparency.
|
|
12145
|
+
* ```typescript
|
|
12146
|
+
* // Load an existing PDF document
|
|
12147
|
+
* let document: PdfDocument = new PdfDocument(data, password);
|
|
12148
|
+
* // Access the list field at index 0
|
|
12149
|
+
* let list1: PdfField = document.form.fieldAt(0);
|
|
12150
|
+
* // Sets the background color of the field.
|
|
12151
|
+
* list1.backColor = [255, 0, 0];
|
|
12152
|
+
* // Access the list field at index 1
|
|
12153
|
+
* let list2: PdfField = document.form.fieldAt(1);
|
|
12154
|
+
* // Sets the background color of the field to transparent.
|
|
12155
|
+
* list2.backColor = [0, 0, 0, 0];
|
|
12156
|
+
* // Save the document
|
|
12157
|
+
* document.save('output.pdf');
|
|
12158
|
+
* // Destroy the document
|
|
12159
|
+
* document.destroy();
|
|
12160
|
+
* ```
|
|
12161
|
+
*/
|
|
12162
|
+
set backColor(value) {
|
|
12163
|
+
this._updateBackColor(value, true);
|
|
12164
|
+
}
|
|
11932
12165
|
get _options() {
|
|
11933
12166
|
if (!this._optionArray) {
|
|
11934
12167
|
if (this._dictionary.has('Opt')) {
|
|
@@ -12546,17 +12779,21 @@ class PdfComboBoxField extends PdfListField {
|
|
|
12546
12779
|
parameter.bounds = [0, 0, bounds.width, bounds.height];
|
|
12547
12780
|
}
|
|
12548
12781
|
const backcolor = item.backColor;
|
|
12549
|
-
|
|
12782
|
+
if (backcolor) {
|
|
12783
|
+
parameter.backBrush = new PdfBrush(backcolor);
|
|
12784
|
+
}
|
|
12550
12785
|
parameter.foreBrush = new PdfBrush(item.color);
|
|
12551
12786
|
const border = item.border;
|
|
12552
12787
|
parameter.borderPen = new PdfPen(item.borderColor, border.width);
|
|
12553
12788
|
parameter.borderStyle = border.style;
|
|
12554
12789
|
parameter.borderWidth = border.width;
|
|
12555
|
-
|
|
12556
|
-
|
|
12557
|
-
shadowColor[
|
|
12558
|
-
|
|
12559
|
-
|
|
12790
|
+
if (backcolor) {
|
|
12791
|
+
const shadowColor = [backcolor[0] - 64, backcolor[1] - 64, backcolor[2] - 64];
|
|
12792
|
+
const color = [shadowColor[0] >= 0 ? shadowColor[0] : 0,
|
|
12793
|
+
shadowColor[1] >= 0 ? shadowColor[1] : 0,
|
|
12794
|
+
shadowColor[2] >= 0 ? shadowColor[2] : 0];
|
|
12795
|
+
parameter.shadowBrush = new PdfBrush(color);
|
|
12796
|
+
}
|
|
12560
12797
|
parameter.rotationAngle = item.rotate;
|
|
12561
12798
|
const alignment = typeof item.textAlignment !== 'undefined' ? item.textAlignment : PdfTextAlignment.left;
|
|
12562
12799
|
const verticalAlignment = this.multiSelect ? PdfVerticalAlignment.top : PdfVerticalAlignment.middle;
|
|
@@ -12576,17 +12813,21 @@ class PdfComboBoxField extends PdfListField {
|
|
|
12576
12813
|
}
|
|
12577
12814
|
}
|
|
12578
12815
|
const backcolor = this.backColor;
|
|
12579
|
-
|
|
12816
|
+
if (backcolor) {
|
|
12817
|
+
parameter.backBrush = new PdfBrush(backcolor);
|
|
12818
|
+
}
|
|
12580
12819
|
parameter.foreBrush = new PdfBrush(this.color);
|
|
12581
12820
|
const border = this.border;
|
|
12582
12821
|
parameter.borderPen = new PdfPen(this.borderColor, border.width);
|
|
12583
12822
|
parameter.borderStyle = border.style;
|
|
12584
12823
|
parameter.borderWidth = border.width;
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
shadowColor[
|
|
12588
|
-
|
|
12589
|
-
|
|
12824
|
+
if (backcolor) {
|
|
12825
|
+
const shadowColor = [backcolor[0] - 64, backcolor[1] - 64, backcolor[2] - 64];
|
|
12826
|
+
const color = [shadowColor[0] >= 0 ? shadowColor[0] : 0,
|
|
12827
|
+
shadowColor[1] >= 0 ? shadowColor[1] : 0,
|
|
12828
|
+
shadowColor[2] >= 0 ? shadowColor[2] : 0];
|
|
12829
|
+
parameter.shadowBrush = new PdfBrush(color);
|
|
12830
|
+
}
|
|
12590
12831
|
parameter.rotationAngle = this.rotationAngle;
|
|
12591
12832
|
const alignment = typeof this.textAlignment !== 'undefined' ? this.textAlignment : PdfTextAlignment.left;
|
|
12592
12833
|
const verticalAlignment = this.multiSelect ? PdfVerticalAlignment.top : PdfVerticalAlignment.middle;
|
|
@@ -12921,17 +13162,21 @@ class PdfListBoxField extends PdfListField {
|
|
|
12921
13162
|
parameter.bounds = [0, 0, bounds.width, bounds.height];
|
|
12922
13163
|
}
|
|
12923
13164
|
const backcolor = item.backColor;
|
|
12924
|
-
|
|
13165
|
+
if (backcolor) {
|
|
13166
|
+
parameter.backBrush = new PdfBrush(backcolor);
|
|
13167
|
+
}
|
|
12925
13168
|
parameter.foreBrush = new PdfBrush(item.color);
|
|
12926
13169
|
const border = item.border;
|
|
12927
13170
|
parameter.borderPen = new PdfPen(item.borderColor, border.width);
|
|
12928
13171
|
parameter.borderStyle = border.style;
|
|
12929
13172
|
parameter.borderWidth = border.width;
|
|
12930
|
-
|
|
12931
|
-
|
|
12932
|
-
shadowColor[
|
|
12933
|
-
|
|
12934
|
-
|
|
13173
|
+
if (backcolor) {
|
|
13174
|
+
const shadowColor = [backcolor[0] - 64, backcolor[1] - 64, backcolor[2] - 64];
|
|
13175
|
+
const color = [shadowColor[0] >= 0 ? shadowColor[0] : 0,
|
|
13176
|
+
shadowColor[1] >= 0 ? shadowColor[1] : 0,
|
|
13177
|
+
shadowColor[2] >= 0 ? shadowColor[2] : 0];
|
|
13178
|
+
parameter.shadowBrush = new PdfBrush(color);
|
|
13179
|
+
}
|
|
12935
13180
|
parameter.rotationAngle = item.rotate;
|
|
12936
13181
|
const alignment = typeof item.textAlignment !== 'undefined' ? item.textAlignment : PdfTextAlignment.left;
|
|
12937
13182
|
const verticalAlignment = this.multiSelect ? PdfVerticalAlignment.top : PdfVerticalAlignment.middle;
|
|
@@ -12949,17 +13194,21 @@ class PdfListBoxField extends PdfListField {
|
|
|
12949
13194
|
parameter.bounds = [0, 0, bounds.width, bounds.height];
|
|
12950
13195
|
}
|
|
12951
13196
|
const backcolor = this.backColor;
|
|
12952
|
-
|
|
13197
|
+
if (backcolor) {
|
|
13198
|
+
parameter.backBrush = new PdfBrush(backcolor);
|
|
13199
|
+
}
|
|
12953
13200
|
parameter.foreBrush = new PdfBrush(this.color);
|
|
12954
13201
|
const border = this.border;
|
|
12955
13202
|
parameter.borderPen = new PdfPen(this.borderColor, border.width);
|
|
12956
13203
|
parameter.borderStyle = border.style;
|
|
12957
13204
|
parameter.borderWidth = border.width;
|
|
12958
|
-
|
|
12959
|
-
|
|
12960
|
-
shadowColor[
|
|
12961
|
-
|
|
12962
|
-
|
|
13205
|
+
if (backcolor) {
|
|
13206
|
+
const shadowColor = [backcolor[0] - 64, backcolor[1] - 64, backcolor[2] - 64];
|
|
13207
|
+
const color = [shadowColor[0] >= 0 ? shadowColor[0] : 0,
|
|
13208
|
+
shadowColor[1] >= 0 ? shadowColor[1] : 0,
|
|
13209
|
+
shadowColor[2] >= 0 ? shadowColor[2] : 0];
|
|
13210
|
+
parameter.shadowBrush = new PdfBrush(color);
|
|
13211
|
+
}
|
|
12963
13212
|
parameter.rotationAngle = this.rotationAngle;
|
|
12964
13213
|
const alignment = typeof this.textAlignment !== 'undefined' ? this.textAlignment : PdfTextAlignment.left;
|
|
12965
13214
|
const verticalAlignment = this.multiSelect ? PdfVerticalAlignment.top : PdfVerticalAlignment.middle;
|
|
@@ -13161,6 +13410,50 @@ class PdfSignatureField extends PdfField {
|
|
|
13161
13410
|
}
|
|
13162
13411
|
return this._isSigned;
|
|
13163
13412
|
}
|
|
13413
|
+
/**
|
|
13414
|
+
* Gets the background color of the field.
|
|
13415
|
+
*
|
|
13416
|
+
* @returns {number[]} R, G, B color values in between 0 to 255.
|
|
13417
|
+
* ```typescript
|
|
13418
|
+
* // Load an existing PDF document
|
|
13419
|
+
* let document: PdfDocument = new PdfDocument(data, password);
|
|
13420
|
+
* // Access the form field at index 0
|
|
13421
|
+
* let field: PdfField = document.form.fieldAt(0);
|
|
13422
|
+
* // Gets the background color of the field.
|
|
13423
|
+
* let backColor: number[] = field.backColor;
|
|
13424
|
+
* // Save the document
|
|
13425
|
+
* document.save('output.pdf');
|
|
13426
|
+
* // Destroy the document
|
|
13427
|
+
* document.destroy();
|
|
13428
|
+
* ```
|
|
13429
|
+
*/
|
|
13430
|
+
get backColor() {
|
|
13431
|
+
return this._parseBackColor(true);
|
|
13432
|
+
}
|
|
13433
|
+
/**
|
|
13434
|
+
* Sets the background color of the field.
|
|
13435
|
+
*
|
|
13436
|
+
* @param {number[]} value Array with R, G, B, A color values in between 0 to 255. For optional A (0-254), it signifies transparency.
|
|
13437
|
+
* ```typescript
|
|
13438
|
+
* // Load an existing PDF document
|
|
13439
|
+
* let document: PdfDocument = new PdfDocument(data, password);
|
|
13440
|
+
* // Access the signature field at index 0
|
|
13441
|
+
* let field1: PdfField = document.form.fieldAt(0);
|
|
13442
|
+
* // Sets the background color of the field.
|
|
13443
|
+
* field1.backColor = [255, 0, 0];
|
|
13444
|
+
* // Access the signature field at index 1
|
|
13445
|
+
* let field2: PdfField = document.form.fieldAt(1);
|
|
13446
|
+
* // Sets the background color of the field to transparent.
|
|
13447
|
+
* field2.backColor = [0, 0, 0, 0];
|
|
13448
|
+
* // Save the document
|
|
13449
|
+
* document.save('output.pdf');
|
|
13450
|
+
* // Destroy the document
|
|
13451
|
+
* document.destroy();
|
|
13452
|
+
* ```
|
|
13453
|
+
*/
|
|
13454
|
+
set backColor(value) {
|
|
13455
|
+
this._updateBackColor(value, true);
|
|
13456
|
+
}
|
|
13164
13457
|
static _load(form, dictionary, crossReference, reference) {
|
|
13165
13458
|
const field = new PdfSignatureField();
|
|
13166
13459
|
field._isLoaded = true;
|
|
@@ -13243,7 +13536,7 @@ class PdfSignatureField extends PdfField {
|
|
|
13243
13536
|
const parameter = new _PaintParameter();
|
|
13244
13537
|
parameter.bounds = [0, 0, bounds.width, bounds.height];
|
|
13245
13538
|
const backcolor = widget.backColor;
|
|
13246
|
-
if (isFlatten) {
|
|
13539
|
+
if (isFlatten && backcolor) {
|
|
13247
13540
|
parameter.backBrush = new PdfBrush(backcolor);
|
|
13248
13541
|
}
|
|
13249
13542
|
parameter.foreBrush = new PdfBrush(widget.color);
|
|
@@ -13251,11 +13544,13 @@ class PdfSignatureField extends PdfField {
|
|
|
13251
13544
|
parameter.borderPen = new PdfPen(widget.borderColor, border.width);
|
|
13252
13545
|
parameter.borderStyle = border.style;
|
|
13253
13546
|
parameter.borderWidth = border.width;
|
|
13254
|
-
|
|
13255
|
-
|
|
13256
|
-
shadowColor[
|
|
13257
|
-
|
|
13258
|
-
|
|
13547
|
+
if (backcolor) {
|
|
13548
|
+
const shadowColor = [backcolor[0] - 64, backcolor[1] - 64, backcolor[2] - 64];
|
|
13549
|
+
const color = [shadowColor[0] >= 0 ? shadowColor[0] : 0,
|
|
13550
|
+
shadowColor[1] >= 0 ? shadowColor[1] : 0,
|
|
13551
|
+
shadowColor[2] >= 0 ? shadowColor[2] : 0];
|
|
13552
|
+
parameter.shadowBrush = new PdfBrush(color);
|
|
13553
|
+
}
|
|
13259
13554
|
parameter.rotationAngle = widget.rotate;
|
|
13260
13555
|
graphics.save();
|
|
13261
13556
|
graphics._initializeCoordinates();
|
|
@@ -23231,7 +23526,7 @@ class PdfSoundAnnotation extends PdfComment {
|
|
|
23231
23526
|
* // Get the first page
|
|
23232
23527
|
* let page: PdfPage = document.getPage(0) as PdfPage;
|
|
23233
23528
|
* // Create a new free text annotation
|
|
23234
|
-
* const annotation: PdfFreeTextAnnotation = new PdfFreeTextAnnotation
|
|
23529
|
+
* const annotation: PdfFreeTextAnnotation = new PdfFreeTextAnnotation(50, 100, 100, 50);
|
|
23235
23530
|
* // Add annotation to the page
|
|
23236
23531
|
* page.annotations.add(annotation);
|
|
23237
23532
|
* // Destroy the document
|
|
@@ -24977,6 +25272,7 @@ class PdfWidgetAnnotation extends PdfAnnotation {
|
|
|
24977
25272
|
this._isAutoResize = false;
|
|
24978
25273
|
this._visibility = PdfFormFieldVisibility.visible;
|
|
24979
25274
|
this._isFont = false;
|
|
25275
|
+
this._isTransparentBackColor = false;
|
|
24980
25276
|
this._isWidget = true;
|
|
24981
25277
|
this._type = _PdfAnnotationType.widgetAnnotation;
|
|
24982
25278
|
}
|
|
@@ -25081,44 +25377,30 @@ class PdfWidgetAnnotation extends PdfAnnotation {
|
|
|
25081
25377
|
* ```typescript
|
|
25082
25378
|
* // Load an existing PDF document
|
|
25083
25379
|
* let document: PdfDocument = new PdfDocument(data, password);
|
|
25084
|
-
* //
|
|
25085
|
-
* let
|
|
25086
|
-
* // Get the first annotation of the page
|
|
25087
|
-
* let annotation: PdfWidgetAnnotation = page.annotations.at(0) as PdfWidgetAnnotation;
|
|
25380
|
+
* // Access the text box field at index 0
|
|
25381
|
+
* let field: PdfField = document.form.fieldAt(0);
|
|
25088
25382
|
* // Gets the back color of the annotation
|
|
25089
|
-
* let backColor: number[] =
|
|
25383
|
+
* let backColor: number[] = field.itemAt(0).backColor;
|
|
25090
25384
|
* // Destroy the document
|
|
25091
25385
|
* document.destroy();
|
|
25092
25386
|
* ```
|
|
25093
25387
|
*/
|
|
25094
25388
|
get backColor() {
|
|
25095
|
-
|
|
25096
|
-
const dictionary = this._mkDictionary;
|
|
25097
|
-
if (dictionary && dictionary.has('BG')) {
|
|
25098
|
-
const colorArray = dictionary.getArray('BG');
|
|
25099
|
-
if (colorArray) {
|
|
25100
|
-
this._backColor = _parseColor(colorArray);
|
|
25101
|
-
}
|
|
25102
|
-
}
|
|
25103
|
-
}
|
|
25104
|
-
if (typeof this._backColor === 'undefined' || this._backColor === null) {
|
|
25105
|
-
this._backColor = [255, 255, 255];
|
|
25106
|
-
}
|
|
25107
|
-
return this._backColor;
|
|
25389
|
+
return this._parseBackColor();
|
|
25108
25390
|
}
|
|
25109
25391
|
/**
|
|
25110
25392
|
* Sets the back color of the annotation.
|
|
25111
25393
|
*
|
|
25112
|
-
* @param {number[]} value
|
|
25394
|
+
* @param {number[]} value Array with R, G, B, A color values in between 0 to 255. For optional A (0-254), it signifies transparency.
|
|
25113
25395
|
* ```typescript
|
|
25114
25396
|
* // Load an existing PDF document
|
|
25115
25397
|
* let document: PdfDocument = new PdfDocument(data, password);
|
|
25116
|
-
* //
|
|
25117
|
-
* let
|
|
25118
|
-
* //
|
|
25119
|
-
*
|
|
25120
|
-
* // Sets the
|
|
25121
|
-
*
|
|
25398
|
+
* // Access the text box field at index 0
|
|
25399
|
+
* let field: PdfField = document.form.fieldAt(0);
|
|
25400
|
+
* // Sets the background color of the field item
|
|
25401
|
+
* field.itemAt(0).backColor = [255, 0, 0];
|
|
25402
|
+
* // Sets the background color of the field item to transparent
|
|
25403
|
+
* field.itemAt(1).backColor = [0, 0, 0, 0];
|
|
25122
25404
|
* // Save the document
|
|
25123
25405
|
* document.save('output.pdf');
|
|
25124
25406
|
* // Destroy the document
|
|
@@ -25126,14 +25408,15 @@ class PdfWidgetAnnotation extends PdfAnnotation {
|
|
|
25126
25408
|
* ```
|
|
25127
25409
|
*/
|
|
25128
25410
|
set backColor(value) {
|
|
25129
|
-
|
|
25130
|
-
|
|
25131
|
-
|
|
25132
|
-
|
|
25133
|
-
|
|
25134
|
-
|
|
25135
|
-
|
|
25136
|
-
|
|
25411
|
+
this._updateBackColor(value);
|
|
25412
|
+
}
|
|
25413
|
+
get _hasBackColor() {
|
|
25414
|
+
if (this._isLoaded) {
|
|
25415
|
+
const mkDictionary = this._mkDictionary;
|
|
25416
|
+
return (mkDictionary && mkDictionary.has('BG'));
|
|
25417
|
+
}
|
|
25418
|
+
else {
|
|
25419
|
+
return !this._isTransparentBackColor;
|
|
25137
25420
|
}
|
|
25138
25421
|
}
|
|
25139
25422
|
/**
|
|
@@ -25769,6 +26052,58 @@ class PdfWidgetAnnotation extends PdfAnnotation {
|
|
|
25769
26052
|
this._dictionary.update('Rect', _getUpdatedBounds([value.x, value.y, value.width, value.height], this._page));
|
|
25770
26053
|
}
|
|
25771
26054
|
}
|
|
26055
|
+
_parseBackColor() {
|
|
26056
|
+
let value;
|
|
26057
|
+
if ((this._isLoaded && this._hasBackColor) || (!this._isLoaded && !this._isTransparentBackColor)) {
|
|
26058
|
+
if (typeof this._backColor === 'undefined') {
|
|
26059
|
+
const dictionary = this._mkDictionary;
|
|
26060
|
+
if (dictionary && dictionary.has('BG')) {
|
|
26061
|
+
const colorArray = dictionary.getArray('BG');
|
|
26062
|
+
if (colorArray) {
|
|
26063
|
+
this._backColor = _parseColor(colorArray);
|
|
26064
|
+
}
|
|
26065
|
+
}
|
|
26066
|
+
}
|
|
26067
|
+
if (typeof this._backColor === 'undefined' || this._backColor === null) {
|
|
26068
|
+
this._backColor = [255, 255, 255];
|
|
26069
|
+
}
|
|
26070
|
+
value = this._backColor;
|
|
26071
|
+
}
|
|
26072
|
+
return value;
|
|
26073
|
+
}
|
|
26074
|
+
_updateBackColor(value, setAppearance = false) {
|
|
26075
|
+
let isChanged = false;
|
|
26076
|
+
if (value.length === 4 && value[3] !== 255) {
|
|
26077
|
+
this._isTransparentBackColor = true;
|
|
26078
|
+
if (this._dictionary.has('BG')) {
|
|
26079
|
+
delete this._dictionary._map.BG;
|
|
26080
|
+
isChanged = true;
|
|
26081
|
+
}
|
|
26082
|
+
const mkDictionary = this._mkDictionary;
|
|
26083
|
+
if (mkDictionary && mkDictionary.has('BG')) {
|
|
26084
|
+
delete mkDictionary._map.BG;
|
|
26085
|
+
this._dictionary._updated = true;
|
|
26086
|
+
isChanged = true;
|
|
26087
|
+
}
|
|
26088
|
+
}
|
|
26089
|
+
else {
|
|
26090
|
+
this._isTransparentBackColor = false;
|
|
26091
|
+
if (typeof this.backColor === 'undefined' || this._backColor !== value) {
|
|
26092
|
+
if (typeof this._mkDictionary === 'undefined') {
|
|
26093
|
+
this._dictionary.update('MK', new _PdfDictionary(this._crossReference));
|
|
26094
|
+
}
|
|
26095
|
+
this._mkDictionary.update('BG', [Number.parseFloat((value[0] / 255).toFixed(3)),
|
|
26096
|
+
Number.parseFloat((value[1] / 255).toFixed(3)),
|
|
26097
|
+
Number.parseFloat((value[2] / 255).toFixed(3))]);
|
|
26098
|
+
this._backColor = [value[0], value[1], value[2]];
|
|
26099
|
+
this._dictionary._updated = true;
|
|
26100
|
+
isChanged = true;
|
|
26101
|
+
}
|
|
26102
|
+
}
|
|
26103
|
+
if (setAppearance && isChanged && this._field) {
|
|
26104
|
+
this._field._setAppearance = true;
|
|
26105
|
+
}
|
|
26106
|
+
}
|
|
25772
26107
|
}
|
|
25773
26108
|
/**
|
|
25774
26109
|
* `PdfStateItem` class represents the check box field item objects.
|
|
@@ -26099,6 +26434,52 @@ class PdfRadioButtonListItem extends PdfStateItem {
|
|
|
26099
26434
|
set value(option) {
|
|
26100
26435
|
this._optionValue = option;
|
|
26101
26436
|
}
|
|
26437
|
+
/**
|
|
26438
|
+
* Gets the back color of the annotation.
|
|
26439
|
+
*
|
|
26440
|
+
* @returns {number[]} Color as R, G, B color array in between 0 to 255.
|
|
26441
|
+
* ```typescript
|
|
26442
|
+
* // Load an existing PDF document
|
|
26443
|
+
* let document: PdfDocument = new PdfDocument(data, password);
|
|
26444
|
+
* // Get the first page
|
|
26445
|
+
* let page: PdfPage = document.getPage(0) as PdfPage;
|
|
26446
|
+
* // Get the first annotation of the page
|
|
26447
|
+
* let annotation: PdfWidgetAnnotation = page.annotations.at(0) as PdfWidgetAnnotation;
|
|
26448
|
+
* // Gets the back color of the annotation
|
|
26449
|
+
* let backColor: number[] = annotation.backColor;
|
|
26450
|
+
* // Destroy the document
|
|
26451
|
+
* document.destroy();
|
|
26452
|
+
* ```
|
|
26453
|
+
*/
|
|
26454
|
+
get backColor() {
|
|
26455
|
+
return this._parseBackColor();
|
|
26456
|
+
}
|
|
26457
|
+
/**
|
|
26458
|
+
* Sets the back color of the annotation.
|
|
26459
|
+
*
|
|
26460
|
+
* @param {number[]} value Array with R, G, B, A color values in between 0 to 255. For optional A (0-254), it signifies transparency.
|
|
26461
|
+
* ```typescript
|
|
26462
|
+
* // Load an existing PDF document
|
|
26463
|
+
* let document: PdfDocument = new PdfDocument(data);
|
|
26464
|
+
* // Gets the first page of the document
|
|
26465
|
+
* let page: PdfPage = document.getPage(0);
|
|
26466
|
+
* // Access the PDF form
|
|
26467
|
+
* let form: PdfForm = document.form;
|
|
26468
|
+
* // Access the radio button list field
|
|
26469
|
+
* let field: PdfRadioButtonListField = form.fieldAt(0) as PdfRadioButtonListField;
|
|
26470
|
+
* // Sets the back color of the radio button list item
|
|
26471
|
+
* field.itemAt(0).backColor = [255, 255, 255];
|
|
26472
|
+
* // Sets the background color of the field item to transparent
|
|
26473
|
+
* field.itemAt(1).backColor = [0, 0, 0, 0];
|
|
26474
|
+
* // Save the document
|
|
26475
|
+
* document.save('output.pdf');
|
|
26476
|
+
* // Destroy the document
|
|
26477
|
+
* document.destroy();
|
|
26478
|
+
* ```
|
|
26479
|
+
*/
|
|
26480
|
+
set backColor(value) {
|
|
26481
|
+
this._updateBackColor(value, true);
|
|
26482
|
+
}
|
|
26102
26483
|
_initializeItem(value, bounds, page, field) {
|
|
26103
26484
|
this._optionValue = value;
|
|
26104
26485
|
this._page = page;
|