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

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

Introduction

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

Prototype

public void addKid(PdfFormField field) 

Source Link

Usage

From source file:at.reppeitsolutions.formbuilder.components.pdf.itext.ITextRadio.java

License:Open Source License

@Override
public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) {
    PdfWriter writer = canvases[0].getPdfWriter();
    PdfFormField radiogroup = PdfFormField.createRadioButton(writer, true);
    radiogroup.setFieldName(UUID.randomUUID().toString());
    if (locked) {
        radiogroup.setFieldFlags(BaseField.READ_ONLY);
    }//from ww  w . j a v  a  2  s.  c o m
    RadioCheckField radio;
    for (int i = 0; i < values.length; i++) {
        try {
            Rectangle rect = getBoxRectangle(rectangle, i);
            radio = new RadioCheckField(writer, rect, null, UUID.randomUUID().toString());
            radio.setBorderColor(GrayColor.GRAYBLACK);
            radio.setBackgroundColor(GrayColor.GRAYWHITE);
            radio.setCheckType(RadioCheckField.TYPE_CIRCLE);
            if (value != null && values[i].equals(value)) {
                radio.setChecked(true);
            }
            PdfFormField field = radio.getRadioField();
            radiogroup.addKid(field);
            addBoxDescription(rectangle, i, values, canvases);
        } catch (IOException ex) {
            Logger.getLogger(ITextRadio.class.getName()).log(Level.SEVERE, null, ex);
        } catch (DocumentException ex) {
            Logger.getLogger(ITextRadio.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    writer.addAnnotation(radiogroup);
}

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

License:Open Source License

private static void addRadioButton(PdfWriter writer, Rectangle rect, PdfFormField radio, String name,
        boolean on) throws IOException, DocumentException {
    RadioCheckField check = new RadioCheckField(writer, rect, null, name);
    check.setCheckType(RadioCheckField.TYPE_CHECK);
    check.setBorderColor(Color.BLACK);
    check.setChecked(on);//www  . j  a  va2s. c  o m
    radio.addKid(check.getRadioField());
}

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);
    }//from w  w w. j  a  va2s . c om

    group.addKid(field);
}

From source file:questions.forms.KidsOnDifferentPages.java

public static void createPdf() {
    Document document = new Document();
    try {//from w  ww  .  j a  v a2  s  .co  m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FORM));
        document.open();

        // create the parent field and its kids
        PdfFormField person = PdfFormField.createEmpty(writer);
        person.setFieldName("person");
        // one kid on page 1
        TextField field1 = new TextField(writer, new Rectangle(0, 0), "name1");
        PdfFormField kid1 = field1.getTextField();
        kid1.setPlaceInPage(1);
        person.addKid(kid1);
        // another kid on page 2
        TextField field2 = new TextField(writer, new Rectangle(0, 0), "name2");
        PdfFormField kid2 = field2.getTextField();
        kid2.setPlaceInPage(2);
        person.addKid(kid2);
        writer.addAnnotation(person);

        // now add the page content
        document.add(createTable(kid1));
        document.newPage();
        document.add(createTable(kid2));
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:questions.forms.RadioButtonsOnDifferentPages.java

private static void addRadioButton(PdfWriter writer, Rectangle rect, PdfFormField radio, String name,
        boolean on, int page) throws IOException, DocumentException {
    RadioCheckField check = new RadioCheckField(writer, rect, null, name);
    check.setCheckType(RadioCheckField.TYPE_CIRCLE);
    check.setChecked(on);/*from ww w . ja  v a 2  s .  c o m*/
    PdfFormField field = check.getRadioField();
    field.setPlaceInPage(page);
    radio.addKid(field);
}

From source file:questions.javascript.AddJavaScriptToForm.java

public static void createPdf(String filename) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
    document.open();// w  w  w .jav a2  s .c  om

    BaseFont bf = BaseFont.createFont();
    PdfContentByte directcontent = writer.getDirectContent();
    directcontent.beginText();
    directcontent.setFontAndSize(bf, 12);
    directcontent.showTextAligned(Element.ALIGN_LEFT, "Married?", 36, 770, 0);
    directcontent.showTextAligned(Element.ALIGN_LEFT, "YES", 58, 750, 0);
    directcontent.showTextAligned(Element.ALIGN_LEFT, "NO", 102, 750, 0);
    directcontent.showTextAligned(Element.ALIGN_LEFT, "Name partner?", 36, 730, 0);
    directcontent.endText();

    PdfFormField married = PdfFormField.createRadioButton(writer, true);
    married.setFieldName("married");
    married.setValueAsName("yes");
    Rectangle rectYes = new Rectangle(40, 766, 56, 744);
    RadioCheckField yes = new RadioCheckField(writer, rectYes, null, "yes");
    yes.setChecked(true);
    married.addKid(yes.getRadioField());
    Rectangle rectNo = new Rectangle(84, 766, 100, 744);
    RadioCheckField no = new RadioCheckField(writer, rectNo, null, "no");
    no.setChecked(false);
    married.addKid(no.getRadioField());
    writer.addAnnotation(married);

    Rectangle rect = new Rectangle(40, 710, 200, 726);
    TextField partner = new TextField(writer, rect, "partner");
    partner.setBorderColor(Color.BLACK);
    partner.setBorderWidth(0.5f);
    writer.addAnnotation(partner.getTextField());

    document.close();
}