Text Fields Handling Single or Multiline Text Fields


A text field in a PDF document is comparable with an input or textarea field you may know from HTML. Anyhow both types are represented by a single implementation in the PDF format. The SetaPDF-FormFiller represents such field type with an instance of the SetaPDF_FormFiller_Field_Text instance.

Getting and Setting Values

As you may expect a text field will hold a string value as its value. It may be accessed with the self-explanatory methods: 


Get the field value.


Set the field value.

Field Type Specific Properties


To check or set a field for the multiline flag following methods are available: 


Check if the multiline flag is set.


Set the multiline flag.

Maximal Length

A text field could be restricted its value length. You may access this property by the getMaxLength() and setMaxLength() methods:


Get the max length property if available.


Set the max length property.


If a maximal length is defined an additional flag could be set that automatically divide the field into as many equally spaced positions (combs) as the maximal length value. The field value is laid out into those combs. 


Check if the comb field flag is set.


Set the comb field flag.

Password Field

The PDF format also defines password fields. You can check for them or define a field to be such one with the following methods: 


Check if the password field flag is set.


Set the password field flag.

Do Not Spell Check

A flag, that defines that the text entered in a field shall not be spell-checked can be handled with following methods: 


Check if the "do not spell check" flag is set.


Set the "do not spell check" flag.

Do Not Scroll

If the value does not fit into the rectangle of a text field the viewer application will display scrollbars if you focus the field. Additionally it will display a plus-sign which should give a hint about unseen content in a field. You can define this behavior with the following methods: 


Check if the "do not scroll" flag is set.


Set the "do not scroll" flag.


// get the fields
$fields = $formFiller->getFields();
// access a field through the ArrayAccess implementation
$fields['my text field']->setValue('A simple test with some chars');
// let's play with a multiline field
$multilineField = $fields->get('a multiline text field');
if (!$multilineField->isMultiline()) { // just as an example...
$multilineField->setValue("Line 1\nLine 2\nLine 3\n...");
// get a value
$value = $fields['age']->getValue();
if ($value < 0) {
    echo 'You should at least be born.';