List of usage examples for com.lowagie.text.pdf TextField setChoiceExports
public void setChoiceExports(String[] choiceExports)
From source file:at.reppeitsolutions.formbuilder.components.pdf.itext.ITextSelect.java
License:Open Source License
@Override public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) { PdfWriter writer = canvases[0].getPdfWriter(); TextField text = new TextField(writer, rectangle, String.format("choice_" + UUID.randomUUID().toString())); text.setBorderStyle(PdfBorderDictionary.STYLE_INSET); text.setChoices(values);/*from ww w . j a v a 2s .c o m*/ text.setFontSize(ITextInputText.FONTSIZE); text.setChoiceExports(text.getChoices()); for (int i = 0; value != null && i < values.length; i++) { if (values[i].equals(value)) { text.setChoiceSelection(i); break; } } try { PdfFormField comboField = text.getComboField(); if (locked) { comboField.setFieldFlags(BaseField.READ_ONLY); } writer.addAnnotation(comboField); } catch (IOException ex) { Logger.getLogger(ITextSelect.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(ITextSelect.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:questions.forms.MultipleChoice.java
public static void createPdf() throws IOException, DocumentException { // step 1/*from ww w . j ava2s .c o m*/ Document document = new Document(); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 TextField field = new TextField(writer, new Rectangle(36, 750, 144, 806), "iText"); field.setFontSize(9); String[] list_options = { "JAVA", "C", "CS", "VB", "PHP" }; field.setChoiceExports(list_options); String[] list_values = { "Java", "C/C++", "C#", "VB", "PHP" }; field.setChoices(list_values); PdfFormField f = field.getListField(); f.setFieldFlags(PdfFormField.FF_MULTISELECT); f.put(PdfName.I, new PdfArray(new int[] { 0, 2 })); writer.addAnnotation(f); // step 5 document.close(); }