Example usage for com.lowagie.text.pdf TextField getListField

List of usage examples for com.lowagie.text.pdf TextField getListField

Introduction

In this page you can find the example usage for com.lowagie.text.pdf TextField getListField.

Prototype

public PdfFormField getListField() throws IOException, DocumentException 

Source Link

Document

Gets a new list field.

Usage

From source file:at.reppeitsolutions.formbuilder.components.pdf.itext.ITextListbox.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.setFontSize(ITextInputText.FONTSIZE);
    text.setOptions(TextField.MULTISELECT);
    text.setChoices(values);//  ww w.  ja  v a  2s. co  m
    ArrayList<Integer> choiceSelections = new ArrayList<>();
    if (selectedValues != null) {
        for (int i = 0; i < values.length; i++) {
            for (int i2 = 0; i2 < selectedValues.length; i2++) {
                if (values[i].equals(selectedValues[i2])) {
                    choiceSelections.add(i);
                    break;
                }
            }
        }
    }
    text.setChoiceSelections(choiceSelections);
    try {
        PdfFormField listField = text.getListField();
        if (locked) {
            listField.setFieldFlags(BaseField.READ_ONLY);
        }
        writer.addAnnotation(listField);
    } catch (IOException ex) {
        Logger.getLogger(ITextListbox.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(ITextListbox.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.geek.tutorial.itext.acroform.ListFieldForm.java

License:Open Source License

public ListFieldForm() throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ListFieldForm.pdf"));
    document.open();/*from  w  ww .j a  v a2  s . c om*/

    // Code 1
    String options[] = { "PS3", "XBOX 360", "Wii", "PSP", "NDS", "GBA" };

    // Code 2 create drop-down list
    PdfFormField dropDown = PdfFormField.createCombo(writer, true, options, 0);
    dropDown.setWidget(new Rectangle(50, 785, 120, 800), PdfAnnotation.HIGHLIGHT_INVERT);
    dropDown.setFieldName("dropDownList");
    dropDown.setValueAsString("PS3");
    dropDown.setMKBorderColor(Color.BLACK);
    writer.addAnnotation(dropDown);

    // Code 3 create scrollable list
    TextField scrollableList = new TextField(writer, new Rectangle(150, 740, 250, 800), "scrollableList");
    scrollableList.setBackgroundColor(Color.WHITE);
    scrollableList.setBorderColor(Color.BLUE);
    scrollableList.setBorderWidth(2);
    scrollableList.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
    scrollableList.setFontSize(10);
    scrollableList.setChoices(options);
    scrollableList.setChoiceSelection(0);
    writer.addAnnotation(scrollableList.getListField());

    // Code 4 add function and button for showing state 
    writer.addJavaScript(
            "function showState(){" + "app.alert('DropDown:'+ this.getField('dropDownList').value +'\\n'+"
                    + "'Scrollable List:'+this.getField('scrollableList').value);" + "}");
    PushbuttonField push = new PushbuttonField(writer, new Rectangle(70, 710, 140, 730), "pushAction");
    push.setBackgroundColor(Color.LIGHT_GRAY);
    push.setBorderColor(Color.GRAY);
    push.setText("Show State");
    push.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
    push.setTextColor(Color.BLACK);
    PdfFormField pushbutton = push.getField();
    pushbutton.setAction(PdfAction.javaScript("showState()", writer));
    writer.addAnnotation(pushbutton);

    document.close();
}

From source file:questions.forms.MultipleChoice.java

public static void createPdf() throws IOException, DocumentException {
    // step 1/*  w  w w .  ja va2 s.  com*/
    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();
}