@@ -259,7 +259,8 @@ public PdfFormField(PdfDictionary pdfObject) {
259
259
260
260
/**
261
261
* Creates a minimal {@link PdfFormField}.
262
- * @param pdfDocument The document
262
+ *
263
+ * @param pdfDocument The document
263
264
*/
264
265
protected PdfFormField (PdfDocument pdfDocument ) {
265
266
this ((PdfDictionary ) new PdfDictionary ().makeIndirect (pdfDocument ));
@@ -272,8 +273,8 @@ protected PdfFormField(PdfDocument pdfDocument) {
272
273
/**
273
274
* Creates a form field as a parent of a {@link PdfWidgetAnnotation}.
274
275
*
275
- * @param widget The widget which will be a kid of the {@link PdfFormField}
276
- * @param pdfDocument The document
276
+ * @param widget The widget which will be a kid of the {@link PdfFormField}
277
+ * @param pdfDocument The document
277
278
*/
278
279
protected PdfFormField (PdfWidgetAnnotation widget , PdfDocument pdfDocument ) {
279
280
this ((PdfDictionary ) new PdfDictionary ().makeIndirect (pdfDocument ));
@@ -699,7 +700,7 @@ public static PdfChoiceFormField createChoice(PdfDocument doc, Rectangle rect, S
699
700
field .put (PdfName .Opt , options );
700
701
field .setFieldFlags (flags );
701
702
field .setFieldName (name );
702
- field .getPdfObject ().put (PdfName .V , new PdfString (value ));
703
+ field .getPdfObject ().put (PdfName .V , new PdfString (value , PdfEncodings . UNICODE_BIG ));
703
704
if ((flags & PdfChoiceFormField .FF_COMBO ) == 0 ) {
704
705
value = field .optionsArrayToString (options );
705
706
}
@@ -1771,7 +1772,7 @@ public PdfObject getRichText() {
1771
1772
* May be either {@link PdfStream} or {@link PdfString}.
1772
1773
*
1773
1774
* @param richText a new rich text value
1774
- * @return The edited PdfFormField
1775
+ * @return The edited PdfFormField
1775
1776
*/
1776
1777
public PdfFormField setRichText (PdfObject richText ) {
1777
1778
getPdfObject ().put (PdfName .RV , richText );
@@ -1793,8 +1794,8 @@ public PdfFont getFont() {
1793
1794
* Note that the font will be added to the document so ensure that the font is embedded
1794
1795
* if it's a pdf/a document.
1795
1796
*
1796
- * @param font The new font to be set
1797
- * @return The edited PdfFormField
1797
+ * @param font The new font to be set
1798
+ * @return The edited PdfFormField
1798
1799
*/
1799
1800
public PdfFormField setFont (PdfFont font ) {
1800
1801
this .font = font ;
@@ -1806,8 +1807,8 @@ public PdfFormField setFont(PdfFont font) {
1806
1807
* Basic setter for the <code>fontSize</code> property. Regenerates the
1807
1808
* field appearance after setting the new value.
1808
1809
*
1809
- * @param fontSize The new font size to be set
1810
- * @return The edited PdfFormField
1810
+ * @param fontSize The new font size to be set
1811
+ * @return The edited PdfFormField
1811
1812
*/
1812
1813
public PdfFormField setFontSize (float fontSize ) {
1813
1814
this .fontSize = fontSize ;
@@ -1819,8 +1820,8 @@ public PdfFormField setFontSize(float fontSize) {
1819
1820
* Basic setter for the <code>fontSize</code> property. Regenerates the
1820
1821
* field appearance after setting the new value.
1821
1822
*
1822
- * @param fontSize The new font size to be set
1823
- * @return The edited PdfFormField
1823
+ * @param fontSize The new font size to be set
1824
+ * @return The edited PdfFormField
1824
1825
*/
1825
1826
public PdfFormField setFontSize (int fontSize ) {
1826
1827
setFontSize ((float ) fontSize );
@@ -1831,9 +1832,9 @@ public PdfFormField setFontSize(int fontSize) {
1831
1832
* Combined setter for the <code>font</code> and <code>fontSize</code>
1832
1833
* properties. Regenerates the field appearance after setting the new value.
1833
1834
*
1834
- * @param font The new font to be set
1835
- * @param fontSize The new font size to be set
1836
- * @return The edited PdfFormField
1835
+ * @param font The new font to be set
1836
+ * @param fontSize The new font size to be set
1837
+ * @return The edited PdfFormField
1837
1838
*/
1838
1839
public PdfFormField setFontAndSize (PdfFont font , int fontSize ) {
1839
1840
this .font = font ;
@@ -1846,8 +1847,8 @@ public PdfFormField setFontAndSize(PdfFont font, int fontSize) {
1846
1847
* Basic setter for the <code>backgroundColor</code> property. Regenerates
1847
1848
* the field appearance after setting the new value.
1848
1849
*
1849
- * @param backgroundColor The new color to be set
1850
- * @return The edited PdfFormField
1850
+ * @param backgroundColor The new color to be set
1851
+ * @return The edited PdfFormField
1851
1852
*/
1852
1853
public PdfFormField setBackgroundColor (Color backgroundColor ) {
1853
1854
this .backgroundColor = backgroundColor ;
@@ -1864,8 +1865,8 @@ public PdfFormField setBackgroundColor(Color backgroundColor) {
1864
1865
* Basic setter for the <code>degRotation</code> property. Regenerates
1865
1866
* the field appearance after setting the new value.
1866
1867
*
1867
- * @param degRotation The new degRotation to be set
1868
- * @return The edited PdfFormField
1868
+ * @param degRotation The new degRotation to be set
1869
+ * @return The edited PdfFormField
1869
1870
*/
1870
1871
public PdfFormField setRotation (int degRotation ) {
1871
1872
if (degRotation % 90 != 0 ) {
@@ -1893,8 +1894,8 @@ public PdfFormField setRotation(int degRotation) {
1893
1894
/**
1894
1895
* Sets the action on all {@link PdfWidgetAnnotation widgets} of this form field.
1895
1896
*
1896
- * @param action The action
1897
- * @return The edited field
1897
+ * @param action The action
1898
+ * @return The edited field
1898
1899
*/
1899
1900
public PdfFormField setAction (PdfAction action ) {
1900
1901
List <PdfWidgetAnnotation > widgets = getWidgets ();
@@ -1912,7 +1913,7 @@ public PdfFormField setAction(PdfAction action) {
1912
1913
* {@link #regenerateField() regenerateField} method
1913
1914
*
1914
1915
* @param checkType the new checkbox marker
1915
- * @return The edited field
1916
+ * @return The edited field
1916
1917
*/
1917
1918
public PdfFormField setCheckType (int checkType ) {
1918
1919
if (checkType < TYPE_CHECK || checkType > TYPE_STAR ) {
@@ -1936,7 +1937,7 @@ public PdfFormField setCheckType(int checkType) {
1936
1937
* Options are: HIDDEN, HIDDEN_BUT_PRINTABLE, VISIBLE, VISIBLE_BUT_DOES_NOT_PRINT
1937
1938
*
1938
1939
* @param visibility visibility option
1939
- * @return The edited field
1940
+ * @return The edited field
1940
1941
*/
1941
1942
public PdfFormField setVisibility (int visibility ) {
1942
1943
switch (visibility ) {
@@ -2095,7 +2096,7 @@ public boolean regenerateField() {
2095
2096
PdfNumber topIndex = this .getPdfObject ().getAsNumber (PdfName .TI );
2096
2097
PdfArray options = getOptions ();
2097
2098
if (null != options ) {
2098
- PdfArray visibleOptions = null != topIndex ? new PdfArray (options .subList (topIndex .intValue (), options .size ()- 1 )) : (PdfArray ) options .clone ();
2099
+ PdfArray visibleOptions = null != topIndex ? new PdfArray (options .subList (topIndex .intValue (), options .size () - 1 )) : (PdfArray ) options .clone ();
2099
2100
value = optionsArrayToString (visibleOptions );
2100
2101
}
2101
2102
}
@@ -2348,8 +2349,8 @@ public float getBorderWidth() {
2348
2349
/**
2349
2350
* Sets the border width for the field.
2350
2351
*
2351
- * @param borderWidth The new border width.
2352
- * @return The edited field
2352
+ * @param borderWidth The new border width.
2353
+ * @return The edited field
2353
2354
*/
2354
2355
public PdfFormField setBorderWidth (float borderWidth ) {
2355
2356
PdfDictionary bs = getWidgets ().get (0 ).getBorderStyle ();
@@ -2616,8 +2617,8 @@ protected Rectangle getRect(PdfDictionary field) {
2616
2617
protected static PdfArray processOptions (String [][] options ) {
2617
2618
PdfArray array = new PdfArray ();
2618
2619
for (String [] option : options ) {
2619
- PdfArray subArray = new PdfArray (new PdfString (option [0 ]));
2620
- subArray .add (new PdfString (option [1 ]));
2620
+ PdfArray subArray = new PdfArray (new PdfString (option [0 ], PdfEncodings . UNICODE_BIG ));
2621
+ subArray .add (new PdfString (option [1 ], PdfEncodings . UNICODE_BIG ));
2621
2622
array .add (subArray );
2622
2623
}
2623
2624
return array ;
@@ -2626,7 +2627,7 @@ protected static PdfArray processOptions(String[][] options) {
2626
2627
protected static PdfArray processOptions (String [] options ) {
2627
2628
PdfArray array = new PdfArray ();
2628
2629
for (String option : options ) {
2629
- array .add (new PdfString (option ));
2630
+ array .add (new PdfString (option , PdfEncodings . UNICODE_BIG ));
2630
2631
}
2631
2632
return array ;
2632
2633
}
@@ -2761,11 +2762,11 @@ protected static Object[] splitDAelements(String da) {
2761
2762
/**
2762
2763
* Draws the visual appearance of text in a form field.
2763
2764
*
2764
- * @param rect The location on the page for the list field
2765
- * @param font a {@link PdfFont}
2766
- * @param fontSize The size of the font
2767
- * @param value The initial value
2768
- * @param appearance The appearance
2765
+ * @param rect The location on the page for the list field
2766
+ * @param font a {@link PdfFont}
2767
+ * @param fontSize The size of the font
2768
+ * @param value The initial value
2769
+ * @param appearance The appearance
2769
2770
*/
2770
2771
protected void drawTextAppearance (Rectangle rect , PdfFont font , float fontSize , String value , PdfFormXObject appearance ) {
2771
2772
PdfStream stream = (PdfStream ) new PdfStream ().makeIndirect (getDocument ());
@@ -2852,11 +2853,11 @@ protected void drawTextAppearance(Rectangle rect, PdfFont font, float fontSize,
2852
2853
/**
2853
2854
* Draws the visual appearance of multiline text in a form field.
2854
2855
*
2855
- * @param rect The location on the page for the list field
2856
- * @param font a {@link PdfFont}
2857
- * @param fontSize The size of the font
2858
- * @param value The initial value
2859
- * @param appearance The appearance
2856
+ * @param rect The location on the page for the list field
2857
+ * @param font a {@link PdfFont}
2858
+ * @param fontSize The size of the font
2859
+ * @param value The initial value
2860
+ * @param appearance The appearance
2860
2861
*/
2861
2862
protected void drawMultiLineTextAppearance (Rectangle rect , PdfFont font , float fontSize , String value , PdfFormXObject appearance ) {
2862
2863
PdfStream stream = (PdfStream ) new PdfStream ().makeIndirect (getDocument ());
@@ -2914,10 +2915,10 @@ protected void drawMultiLineTextAppearance(Rectangle rect, PdfFont font, float f
2914
2915
/**
2915
2916
* Draws a border using the borderWidth and borderColor of the form field.
2916
2917
*
2917
- * @param canvas The {@link PdfCanvas} on which to draw
2918
- * @param xObject The PdfFormXObject
2919
- * @param width The width of the rectangle to draw
2920
- * @param height The height of the rectangle to draw
2918
+ * @param canvas The {@link PdfCanvas} on which to draw
2919
+ * @param xObject The PdfFormXObject
2920
+ * @param width The width of the rectangle to draw
2921
+ * @param height The height of the rectangle to draw
2921
2922
*/
2922
2923
protected void drawBorder (PdfCanvas canvas , PdfFormXObject xObject , float width , float height ) {
2923
2924
canvas .saveState ();
@@ -3324,21 +3325,20 @@ private void applyRotation(PdfFormXObject xObject, float height, float width) {
3324
3325
}
3325
3326
}
3326
3327
3327
- private String optionsArrayToString (PdfArray options ) {
3328
- String value = "" ;
3328
+ private static String optionsArrayToString (PdfArray options ) {
3329
+ StringBuilder stringBuilder = new StringBuilder () ;
3329
3330
for (PdfObject obj : options ) {
3330
3331
if (obj .isString ()) {
3331
- value += (( PdfString ) obj ).toUnicodeString () + '\n' ;
3332
+ stringBuilder . append ((( PdfString ) obj ).toUnicodeString ()). append ( '\n' ) ;
3332
3333
} else if (obj .isArray ()) {
3333
3334
PdfObject element = ((PdfArray ) obj ).get (1 );
3334
3335
if (element .isString ()) {
3335
- value += (( PdfString ) element ).toUnicodeString () + '\n' ;
3336
+ stringBuilder . append ((( PdfString ) element ).toUnicodeString ()). append ( '\n' ) ;
3336
3337
}
3337
3338
}
3338
3339
}
3339
- value = value .substring (0 , value .length () - 1 );
3340
-
3341
- return value ;
3340
+ stringBuilder .deleteCharAt (stringBuilder .length () - 1 ); // last '\n'
3341
+ return stringBuilder .toString ();
3342
3342
}
3343
3343
3344
3344
private static double degreeToRadians (double angle ) {
0 commit comments