@@ -629,7 +629,7 @@ public static PdfChoiceFormField createChoice(PdfDocument doc, Rectangle rect, S
629
629
field .put (PdfName .Opt , options );
630
630
field .setFieldFlags (flags );
631
631
field .setFieldName (name );
632
- field .getPdfObject ().put (PdfName .V , new PdfString (value ));
632
+ field .getPdfObject ().put (PdfName .V , new PdfString (value , PdfEncodings . UNICODE_BIG ));
633
633
if ((flags & PdfChoiceFormField .FF_COMBO ) == 0 ) {
634
634
value = field .optionsArrayToString (options );
635
635
}
@@ -1898,12 +1898,11 @@ public boolean regenerateField() {
1898
1898
1899
1899
} else {
1900
1900
if (!getFieldFlag (PdfChoiceFormField .FF_COMBO )) {
1901
- PdfNumber topIndex = ((PdfChoiceFormField ) this ).getTopIndex ();
1902
- PdfArray options = (PdfArray ) getOptions ().clone ();
1903
- if (topIndex != null ) {
1904
- PdfObject object = options .get (topIndex .intValue ());
1905
- options .remove (topIndex .intValue ());
1906
- options .add (0 , object );
1901
+ PdfNumber topIndex = this .getPdfObject ().getAsNumber (PdfName .TI );
1902
+ PdfArray options = getOptions ();
1903
+ if (null != options ) {
1904
+ PdfArray visibleOptions = null != topIndex ? new PdfArray (options .subList (topIndex .intValue (), options .size () - 1 )) : (PdfArray ) options .clone ();
1905
+ value = optionsArrayToString (visibleOptions );
1907
1906
}
1908
1907
value = optionsArrayToString (options );
1909
1908
}
@@ -2424,8 +2423,8 @@ protected Rectangle getRect(PdfDictionary field) {
2424
2423
protected static PdfArray processOptions (String [][] options ) {
2425
2424
PdfArray array = new PdfArray ();
2426
2425
for (String [] option : options ) {
2427
- PdfArray subArray = new PdfArray (new PdfString (option [0 ]));
2428
- subArray .add (new PdfString (option [1 ]));
2426
+ PdfArray subArray = new PdfArray (new PdfString (option [0 ], PdfEncodings . UNICODE_BIG ));
2427
+ subArray .add (new PdfString (option [1 ], PdfEncodings . UNICODE_BIG ));
2429
2428
array .add (subArray );
2430
2429
}
2431
2430
return array ;
@@ -2434,7 +2433,7 @@ protected static PdfArray processOptions(String[][] options) {
2434
2433
protected static PdfArray processOptions (String [] options ) {
2435
2434
PdfArray array = new PdfArray ();
2436
2435
for (String option : options ) {
2437
- array .add (new PdfString (option ));
2436
+ array .add (new PdfString (option , PdfEncodings . UNICODE_BIG ));
2438
2437
}
2439
2438
return array ;
2440
2439
}
@@ -3223,21 +3222,20 @@ private void applyRotation(PdfFormXObject xObject, float height, float width) {
3223
3222
}
3224
3223
}
3225
3224
3226
- private String optionsArrayToString (PdfArray options ) {
3227
- String value = "" ;
3225
+ private static String optionsArrayToString (PdfArray options ) {
3226
+ StringBuilder stringBuilder = new StringBuilder () ;
3228
3227
for (PdfObject obj : options ) {
3229
3228
if (obj .isString ()) {
3230
- value += (( PdfString ) obj ).toUnicodeString () + '\n' ;
3229
+ stringBuilder . append ((( PdfString ) obj ).toUnicodeString ()). append ( '\n' ) ;
3231
3230
} else if (obj .isArray ()) {
3232
3231
PdfObject element = ((PdfArray ) obj ).get (1 );
3233
3232
if (element .isString ()) {
3234
- value += (( PdfString ) element ).toUnicodeString () + '\n' ;
3233
+ stringBuilder . append ((( PdfString ) element ).toUnicodeString ()). append ( '\n' ) ;
3235
3234
}
3236
3235
}
3237
3236
}
3238
- value = value .substring (0 , value .length () - 1 );
3239
-
3240
- return value ;
3237
+ stringBuilder .deleteCharAt (stringBuilder .length () - 1 ); // last '\n'
3238
+ return stringBuilder .toString ();
3241
3239
}
3242
3240
3243
3241
private static double degreeToRadians (double angle ) {
0 commit comments