Example usage for com.lowagie.text.pdf PdfFormField createCombo

List of usage examples for com.lowagie.text.pdf PdfFormField createCombo

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfFormField createCombo.

Prototype

public static PdfFormField createCombo(PdfWriter writer, boolean edit, String options[][], int topIndex) 

Source Link

Usage

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  w w  .j a v a2s  .  co  m*/

    // 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:org.xhtmlrenderer.pdf.SelectFormField.java

License:Open Source License

public void paint(RenderingContext c, ITextOutputDevice outputDevice, BlockBox box) {
    PdfWriter writer = outputDevice.getWriter();

    String[][] options = getPDFOptions();
    int selectedIndex = getSelectedIndex();

    PdfFormField field;/*from   www  .  j  av a2  s.  co m*/

    /*
     * Comment out for now.  We need to draw an appropriate appearance for
     * this to work correctly.
     */
    /*
    if (isMultiple(box.getElement())) {
    field = PdfFormField.createList(writer, options, selectedIndex);  
    } else {
    field = PdfFormField.createCombo(writer, false, options, selectedIndex);    
    }
    */

    field = PdfFormField.createCombo(writer, false, options, selectedIndex);

    field.setWidget(outputDevice.createLocalTargetArea(c, box), PdfAnnotation.HIGHLIGHT_INVERT);
    field.setFieldName(getFieldName(outputDevice, box.getElement()));
    if (options.length > 0) {
        field.setValueAsString(options[selectedIndex][0]);
    }

    createAppearance(c, outputDevice, box, field);

    if (isReadOnly(box.getElement())) {
        field.setFieldFlags(PdfFormField.FF_READ_ONLY);
    }

    /*
    if (isMultiple(box.getElement())) {
    field.setFieldFlags(PdfFormField.FF_MULTISELECT);
    }
    */

    writer.addAnnotation(field);
}