TextBoxField Class
A text box form field in a PDF document.
Declaration
public class TextBoxField extends FormField
Remarks
The following code snippet creates a text field:
import com.devexpress.docs.pdf.*;
import com.devexpress.system.drawing.*;
import com.devexpress.drawing.printing.DXPaperKind;
import java.nio.channels.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
try (PdfDocument pdfDocument = new PdfDocument()) {
// Add an A4 page to the document.
Page page = pdfDocument.getPages().add(DXPaperKind.A4);
// Create a text field.
TextBoxField loginField = new TextBoxField("Login");
// Assign an initial value to the field before it is displayed.
loginField.setValue("John Doe");
pdfDocument.getFields().add(loginField);
// Bind the field to a widget and place it on the page.
RectangleF bounds = new RectangleF(120, 720, 220, 20);
TextBoxWidgetAnnotation widget = new TextBoxWidgetAnnotation(loginField, bounds);
widget.setFontSize(12);
page.getAnnotations().add(widget);
// Save the document.
try (WritableByteChannel channel =
FileChannel.open(Path.of("result.pdf"),
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.TRUNCATE_EXISTING)) {
pdfDocument.save(channel);
}
}
}
}
Refer to the following help topic for additional information: Create a Text Field.
Inherited Members
Inheritance
TextBoxField(String name)
Initializes a new instance of the TextBoxField class with specified settings.
Declaration
public TextBoxField(String name)
Parameters
| Name | Type | Description |
|---|---|---|
| name | String | The name of the text box field. |
Methods
getMaxLength() Method
Returns the maximum number of characters allowed in the text box.
Declaration
public int getMaxLength()
Returns
| Type | Description |
|---|---|
| int | The maximum number of characters allowed in the text box. |
getMultiline() Method
Returns whether the text box accepts multiple lines of text.
Declaration
public boolean getMultiline()
Returns
| Type | Description |
|---|---|
| boolean |
|
getScrollable() Method
Returns whether the text box content can be scrolled.
Declaration
public boolean getScrollable()
Returns
| Type | Description |
|---|---|
| boolean |
|
getSpellCheck() Method
Returns whether spell checking is enabled for the text box.
Declaration
public boolean getSpellCheck()
Returns
| Type | Description |
|---|---|
| boolean |
|
getType() Method
Returns the text field type.
Declaration
public FormFieldTextFieldType getType()
Returns
| Type | Description |
|---|---|
| FormFieldTextFieldType | The text field type. |
getValue() Method
Returns the current text box value.
Declaration
public String getValue()
Returns
| Type | Description |
|---|---|
| String | The current text box value. |
getValueFormat() Method
Returns formatting and validation settings for text box values.
Declaration
public FormFieldValueFormat getValueFormat()
Returns
| Type | Description |
|---|---|
| FormFieldValueFormat | Formatting and validation settings. |
setMaxLength(int value) Method
Sets the maximum number of characters allowed in the text box.
Declaration
public void setMaxLength(int value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | int | The maximum number of characters allowed in the text box. |
setMultiline(boolean value) Method
Sets whether the text box accepts multiple lines of text.
Declaration
public void setMultiline(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|
setScrollable(boolean value) Method
Sets whether the text box content can be scrolled.
Declaration
public void setScrollable(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|
setSpellCheck(boolean value) Method
Sets whether to enable spell checking.
Declaration
public void setSpellCheck(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|
setType(FormFieldTextFieldType value) Method
Sets the text field type.
Declaration
public void setType(FormFieldTextFieldType value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | FormFieldTextFieldType | The text field type. |
setValue(String value) Method
Sets the current text box value.
Declaration
public void setValue(String value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | String | The text to assign to the text box. |
setValueFormat(FormFieldValueFormat value) Method
Sets formatting and validation settings for text box values.
Declaration
public void setValueFormat(FormFieldValueFormat value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | FormFieldValueFormat | Formatting and validation settings for text box values. |
Remarks
The following code snippet configures a text field to accept dates in the MMMM/dd/yyyy format:
// Create a text field.
TextBoxField dateField = new TextBoxField("Date");
// Apply a date format.
dateField.setValueFormat(FormFieldValueFormat.createDateTimeFormat("MMMM/dd/yyyy"));
pdfDocument.getFields().add(dateField);
Refer to the following help topic for additional information: Format and Validate PDF Form Field Values.