import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfAnnotation;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfFormField;
import com.lowagie.text.pdf.PdfWriter;
public class FormComboPDF {
public static void main(String[] args) {
Document document = new Document(PageSize.A4);
try {
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("FormComboPDF.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
cb.moveTo(0, 0);
String options[] = { "A", "B", "C" };
PdfFormField field = PdfFormField.createCombo(writer, true, options, 0);
field.setWidget(new Rectangle(100, 700, 180, 720), PdfAnnotation.HIGHLIGHT_INVERT);
field.setFieldName("ACombo");
field.setValueAsString("B");
writer.addAnnotation(field);
} catch (Exception e) {
System.err.println(e.getMessage());
}
document.close();
}
}
|