com.justformspdf.pdf
Class FormText

java.lang.Object
  |
  +--com.justformspdf.lib.PDFObjectImp
        |
        +--com.justformspdf.lib.PDFObjectGeneric
              |
              +--com.justformspdf.pdf.FormElement
                    |
                    +--com.justformspdf.pdf.FormText
All Implemented Interfaces:
com.justformspdf.lib.PDFObject

public class FormText
extends FormElement

This class represents the Text Box element of PDF Form.

The text box allows input of information in text or numerical form. Text Box fields can be single or multi-line.

Here is an example of filling in a Text Box element.

 
 FileInputStream fis = new FileInputStream("C:\\JustFormsPDF\\examples\\AddressForm32A2.pdf"); 
 PDF pdf = new PDF(new PDFReader(fis));
 Form form = pdf.getForm();

 FormText text = (FormText) form.getElement("Name");
 text.setValue("John K. Baker");


 pdf.render();
 pdf.writeTo(new FileOutputStream("C:\\JustFormsPDF\\examples\\AddressForm32A2_out.pdf"));
 
 


Field Summary
 
Fields inherited from class com.justformspdf.pdf.FormElement
JUSTIFICATION_CENTER, JUSTIFICATION_LEFT, JUSTIFICATION_RIGHT
  
Constructor Summary
FormText(java.lang.String name)
           
 
Method Summary
 void setValue(java.lang.String value)
          Set value of this form element.
boolean isMultiline()
          Get the value of multiline flag
 
Methods inherited from class com.justformspdf.pdf.FormElement
getName,getType,getRect,getValue,setReadOnly,isReadOnly
    

Constructor Detail

FormText

public FormText(java.lang.String name)
Method Detail

setValue

public void setValue(java.lang.String value)
              throws java.lang.Exception
Set value of this form element. (Method inherited from class com.justformspdf.pdf.FormElement)

This method is applibale to all type of form elements.

 

Here is an example of filling in a Text Box element.

 
 FileInputStream fis = new FileInputStream("C:\\JustFormsPDF\\examples\\AddressForm32A2.pdf"); 
 PDF pdf = new PDF(new PDFReader(fis));
 Form form = pdf.getForm();
 FormText text = (FormText) form.getElement("Name");
 text.setValue("John K. Baker");


 pdf.render();
 pdf.writeTo(new FileOutputStream("C:\\JustFormsPDF\\examples\\AddressForm32A2_out.pdf"));
 
Multiline Text: The setValue method is also applicable to multi-line text fields. The text will be auto-wrapped inside the field.
A line break can be enforced using a special text sequence "\\r" in a long text. Here is an example of auto-wrapped multiline and forced-line-break text.
 
 

 FormText comments = (FormText) form.getElement("comments");
 String commentsStr = "The JustFormsPDF library is a Java class library for " + 
                "filling or editing interactive PDF forms on-the-fly. Empower " + 
                "your applications with the industry-standard PDF forms technology " + 
                "using JustFormsPDF. ";
 comments.setValue(commentsStr);

 FormText address = (FormText) form.getElement("address");
 address.setValue("37254 Spring Valley Av.\\rSimi Valley, CA 93063\\r1-800-222-3333");
 
 
 

Overrides:
setValue in class FormElement
Parameters:
value -
Throws:
java.lang.Exception

isMultiline

public boolean isMultiline()
Get the value of Multiline flag of this form element.

Returns:
flag - true if the field is multiline otherwise false