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

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

Introduction

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

Prototype

public void setWidget(Rectangle rect, PdfName highlight) 

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();/* w  ww .  j av  a2s.  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:org.xhtmlrenderer.pdf.RadioButtonFormField.java

License:Open Source License

private void createField(RenderingContext c, ITextOutputDevice outputDevice, PdfContentByte cb,
        PdfWriter writer, PdfFormField group, RadioButtonFormField fieldElem, RadioButtonFormField checked) {
    Box box = fieldElem.getBox();

    Element e = box.getElement();
    String onValue = getValue(e);

    float width = outputDevice.getDeviceLength(fieldElem.getWidth());
    float height = outputDevice.getDeviceLength(fieldElem.getHeight());

    PdfFormField field = PdfFormField.createEmpty(writer);

    FSColor color = box.getStyle().getColor();
    FSColor darker = box.getEffBackgroundColor(c).darkenColor();
    createAppearances(cb, field, onValue, width, height, true, color, darker);
    createAppearances(cb, field, onValue, width, height, false, color, darker);

    field.setWidget(outputDevice.createTargetArea(c, box), PdfAnnotation.HIGHLIGHT_INVERT);

    // XXX createTargetArea already looks up the page, but hopefully a document
    // won't have enough radio buttons to matter
    Rectangle bounds = box.getContentAreaEdge(box.getAbsX(), box.getAbsY(), c);
    PageBox page = c.getRootLayer().getPage(c, bounds.y);
    field.setPlaceInPage(page.getPageNo() + 1);

    field.setBorderStyle(new PdfBorderDictionary(0.0f, 0));

    field.setAppearanceState(fieldElem == checked ? onValue : OFF_STATE);

    if (isReadOnly(e)) {
        field.setFieldFlags(PdfFormField.FF_READ_ONLY);
    }/*  www  . ja  va 2 s. com*/

    group.addKid(field);
}

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   w ww.j a v  a  2s.c o 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);
}