Skip to content

Commit 09d8f30

Browse files
committed
Fix PdfFormField appearance generation in corner cases and fix a sample
1 parent 9162ba9 commit 09d8f30

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

forms/src/main/java/com/itextpdf/forms/fields/PdfFormField.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,20 @@ public static PdfTextFormField createText(PdfDocument doc) {
222222
public static PdfTextFormField createText(PdfDocument doc, Rectangle rect) {
223223
PdfWidgetAnnotation annot = new PdfWidgetAnnotation(rect);
224224
return new PdfTextFormField(annot, doc);
225+
}
225226

227+
/**
228+
* Creates a named {@link PdfTextFormField text form field} with an initial
229+
* value, and the form's default font specified in
230+
* {@link com.itextpdf.forms.PdfAcroForm#getDefaultResources}.
231+
*
232+
* @param doc the {@link PdfDocument} to create the text field in
233+
* @param rect the location on the page for the text field
234+
* @param name the name of the form field
235+
* @return a new {@link PdfTextFormField}
236+
*/
237+
public static PdfTextFormField createText(PdfDocument doc, Rectangle rect, String name) {
238+
return createText(doc, rect, name, "");
226239
}
227240

228241
/**
@@ -1910,7 +1923,7 @@ protected PdfFormXObject drawMultiLineTextAppearance(Rectangle rect, PdfFont fon
19101923
clip().
19111924
newPath();
19121925

1913-
Canvas modelCanvas = new Canvas(canvas, getDocument(), new Rectangle(3, 0, width - 6, height - 2));
1926+
Canvas modelCanvas = new Canvas(canvas, getDocument(), new Rectangle(3, 0, Math.max(0, width - 6), Math.max(0, height - 2)));
19141927
Paragraph paragraph = new Paragraph(value).setFont(font).setFontSize(fontSize).setMargins(0, 0, 0, 0).setMultipliedLeading(1);
19151928
setParagraphProperties(paragraph, value);
19161929
if (value != null && value.length() > 0) {

0 commit comments

Comments
 (0)