import java.awt.Color;
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfAction;
import com.lowagie.text.pdf.PdfBorderDictionary;
import com.lowagie.text.pdf.PdfFormField;
import com.lowagie.text.pdf.PdfName;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.TextField;
public class MainClass {
public static void main(String[] args) throws Exception {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
document.open();
TextField textfield = new TextField(writer, new Rectangle(140, 790, 200, 810), "uppercase");
textfield.setMaxCharacterLength(4);
textfield.setOptions(TextField.COMB);
textfield.setBorderWidth(1);
textfield.setBorderStyle(PdfBorderDictionary.STYLE_INSET);
PdfFormField field = textfield.getTextField();
field.setAdditionalActions(new PdfName("Fo"), PdfAction.javaScript("app.alert('hi');", writer));
writer.addAnnotation(field);
TextField date = new TextField(writer, new Rectangle(140, 760, 250, 780), "date");
date.setOptions(TextField.EDIT);
date.setChoices(new String[] { "A", "Date" });
date.setChoiceExports(new String[] { "12-25-2008", "01-01-2009" });
field = date.getComboField();
field.setAdditionalActions(PdfName.K, PdfAction.javaScript(
"AFDate_KeystrokeEx( 'dd-mm-yyyy' )", writer));
writer.addAnnotation(field);
document.close();
}
}
29.58.TextField |
| 29.58.1. | Field Actions |