DocumentBuilderInsertTextInput Method

Inserts a text form field at the current position.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 22.1.0

ExpandedSyntax

public FormField InsertTextInput(
	string name,
	TextFormFieldType type,
	string format,
	string fieldValue,
	int maxLength
)

Parameters

name
Type: SystemString
The name of the form field. Can be an empty string.
type
Type: Aspose.Words.FieldsTextFormFieldType
Specifies the type of the text form field.
format
Type: SystemString
Format string used to format the value of the form field.
fieldValue
Type: SystemString
Text that will be shown in the field.
maxLength
Type: SystemInt32
Maximum length the user can enter into the form field. Set to zero for unlimited length.

Return Value

Type: FormField
The form field node that was just inserted.

ExpandedRemarks

If you specify a name for the form field, then a bookmark is automatically created with the same name.

ExpandedExamples

Shows how to insert a text input form field into a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a form that prompts the user to enter text.
builder.InsertTextInput("TextInput", TextFormFieldType.Regular, "", "Enter your text here", 0);

doc.Save(ArtifactsDir + "DocumentBuilder.InsertTextInput.docx");
Shows how to insert a text input form field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Write("Please enter text here: ");

// Insert a text input field, which will allow the user to click it and enter text.
// Assign some placeholder text that the user may overwrite and pass
// a maximum text length of 0 to apply no limit on the form field's contents.
builder.InsertTextInput("TextInput1", TextFormFieldType.Regular, "", "Placeholder text", 0);

// The form field will appear in the form of an "input" html tag, with a type of "text".
doc.Save(ArtifactsDir + "FormFields.TextInput.html");
Shows how to create form fields.
DocumentBuilder builder = new DocumentBuilder();

// Form fields are objects in the document that the user can interact with by being prompted to enter values.
// We can create them using a document builder, and below are two ways of doing so.
// 1 -  Basic text input:
builder.InsertTextInput("My text input", TextFormFieldType.Regular, 
    "", "Enter your name here", 30);

// 2 -  Combo box with prompt text, and a range of possible values:
string[] items =
{
    "-- Select your favorite footwear --", "Sneakers", "Oxfords", "Flip-flops", "Other"
};

builder.InsertParagraph();
builder.InsertComboBox("My combo box", items, 0);

builder.Document.Save(ArtifactsDir + "DocumentBuilder.CreateForm.docx");

ExpandedSee Also