{filelink=10430}
/***** Code de MesExemples.com *******/
/**
* @(#)ExempleComboPDF.java
*
*
* @author
*sakoba(java.mesexemples.com) @version 1.00 2013/4/30
*/
import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfAnnotation;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfFormField;
import com.itextpdf.text.pdf.PdfWriter;
public class ExempleComboPDF {
public static void main(String[] args) {
Document document = new Document(PageSize.A4);
try {
PdfWriter pdf_writer = PdfWriter.getInstance(document,
new FileOutputStream("c:/ExempleComboPDF.pdf"));
document.open();
PdfContentByte cb = pdf_writer.getDirectContent();
cb.moveTo(0, 0);
String options[] = { "A", "B", "C", "D" };
// Créer un formulaire de combo
PdfFormField field = PdfFormField.createCombo(pdf_writer, true, options,
0);
field.setWidget(new Rectangle(100, 700, 180, 720),
PdfAnnotation.HIGHLIGHT_INVERT);
field.setFieldName("ACombo");
field.setValueAsString("B");
pdf_writer.addAnnotation(field);
} catch (Exception err) {
System.err.println(err.getMessage());
}
document.close();
}
}