Form List Control : Form Control « PDF RTF « Java






Form List Control

Form List Control
import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.PageSize;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfAnnotation;
import com.lowagie.text.pdf.PdfAppearance;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfFormField;
import com.lowagie.text.pdf.PdfWriter;

public class FormListPDF {
  public static void main(String[] args) {
    Document document = new Document(PageSize.A4);
    try {
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("FormListPDF.pdf"));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
      cb.moveTo(0, 0);
      String options[] = { "A", "B", "C" };
      PdfFormField field = PdfFormField.createList(writer, options, 0);
      field.setWidget(new Rectangle(100, 700, 180, 760), PdfAnnotation.HIGHLIGHT_OUTLINE);
      field.setFieldName("AList");
      field.setValueAsString("B");
      writer.addAnnotation(field);

    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
    document.close();
  }
}
           
       








itext.zip( 1,748 k)

Related examples in the same category

1.TextFields DemoTextFields Demo
2.Form ComboForm Combo