Example usage for com.lowagie.text.pdf RadioCheckField RadioCheckField

List of usage examples for com.lowagie.text.pdf RadioCheckField RadioCheckField

Introduction

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

Prototype

public RadioCheckField(PdfWriter writer, Rectangle box, String fieldName, String onValue) 

Source Link

Document

Creates a new instance of RadioCheckField

Usage

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

License:Open Source License

@Override
public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) {
    PdfWriter writer = canvases[0].getPdfWriter();
    PdfAppearance[] onOff = new PdfAppearance[2];
    onOff[0] = canvases[0].createAppearance(20, 20);
    onOff[0].rectangle(1, 1, 18, 18);//from   www .j  a v a2  s  .c  om
    onOff[0].stroke();
    onOff[1] = canvases[0].createAppearance(20, 20);
    onOff[1].setRGBColorFill(255, 128, 128);
    onOff[1].rectangle(1, 1, 18, 18);
    onOff[1].fillStroke();
    onOff[1].moveTo(1, 1);
    onOff[1].lineTo(19, 19);
    onOff[1].moveTo(1, 19);
    onOff[1].lineTo(19, 1);
    onOff[1].stroke();
    RadioCheckField checkbox;
    Font f = new Font();
    f.setSize(ITextInputText.FONTSIZE);
    for (int i = 0; i < values.length; i++) {
        try {
            Rectangle rect = ITextRadio.getBoxRectangle(rectangle, i);
            checkbox = new RadioCheckField(writer, rect, UUID.randomUUID().toString(), "Yes");
            boolean checked = false;
            if (selectedValues != null) {
                for (int i2 = 0; i2 < selectedValues.length; i2++) {
                    if (values[i].equals(selectedValues[i2])) {
                        checked = true;
                        break;
                    }
                }
            }
            checkbox.setChecked(checked);
            PdfFormField field = checkbox.getCheckField();
            field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0]);
            field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Yes", onOff[1]);
            if (locked) {
                field.setFieldFlags(BaseField.READ_ONLY);
            }
            writer.addAnnotation(field);
            ITextRadio.addBoxDescription(rectangle, i, values, canvases);
        } catch (IOException ex) {
            Logger.getLogger(ITextCheckbox.class.getName()).log(Level.SEVERE, null, ex);
        } catch (DocumentException ex) {
            Logger.getLogger(ITextCheckbox.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

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);
    }/*  ww w  .j  a v  a2s  .  com*/
    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:buckley.compile.CheckboxFieldFactory.java

License:Apache License

public RadioCheckField build(PdfWriter writer, Rectangle size, String name) {
    return new RadioCheckField(writer, size, name, "");
}

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);//from ww w  .j  av a 2s  .  c o m
    radio.addKid(check.getRadioField());
}

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

License:Open Source License

private static void addCheckbox(PdfWriter writer, Rectangle rect, String name)
        throws IOException, DocumentException {
    RadioCheckField check = new RadioCheckField(writer, rect, name, "On");
    check.setCheckType(RadioCheckField.TYPE_CROSS);
    check.setBorderColor(Color.BLACK);
    writer.addAnnotation(check.getCheckField());
}

From source file:org.xhtmlrenderer.pdf.CheckboxFormField.java

License:Open Source License

public void paint(RenderingContext c, ITextOutputDevice outputDevice, BlockBox box) {
    PdfContentByte cb = outputDevice.getCurrentPage();

    PdfWriter writer = outputDevice.getWriter();
    Element elm = box.getElement();

    Rectangle targetArea = outputDevice.createLocalTargetArea(c, box);
    String onValue = getValue(elm);

    RadioCheckField field = new RadioCheckField(writer, targetArea, getFieldName(outputDevice, elm), onValue);

    field.setChecked(isChecked(elm));/*  www.java 2 s.  c  om*/
    field.setCheckType(RadioCheckField.TYPE_CHECK);
    field.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
    //TODO Consider if we can get some more correct color
    field.setBorderColor(Color.black);

    field.setBorderWidth(BaseField.BORDER_WIDTH_THIN);

    try {
        PdfFormField formField = field.getCheckField();
        if (isReadOnly(elm)) {
            formField.setFieldFlags(PdfFormField.FF_READ_ONLY);
        }
        writer.addAnnotation(formField);
    } catch (IOException ioe) {
        System.out.println(ioe);
    } catch (DocumentException de) {
        System.out.println(de);
    }

}

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);//  ww w  .  java  2 s . co 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();//www. j a va  2  s .  c  o  m

    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();
}