Example usage for com.lowagie.text.pdf BaseField READ_ONLY

List of usage examples for com.lowagie.text.pdf BaseField READ_ONLY

Introduction

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

Prototype

int READ_ONLY

To view the source code for com.lowagie.text.pdf BaseField READ_ONLY.

Click Source Link

Document

The user may not change the value of the field.

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  w w w  . j  a  v  a 2s.c  o m*/
    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.ITextInputText.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("text_" + UUID.randomUUID().toString()));
    text.setBorderStyle(PdfBorderDictionary.STYLE_INSET);
    text.setText(value);//from w w  w.j  a  va  2  s.co  m
    text.setFontSize(FONTSIZE);
    text.setAlignment(Element.ALIGN_LEFT);
    try {
        PdfFormField field = text.getTextField();
        if (locked) {
            field.setFieldFlags(BaseField.READ_ONLY);
        }
        writer.addAnnotation(field);
    } catch (IOException ioe) {
        throw new ExceptionConverter(ioe);
    } catch (DocumentException de) {
        throw new ExceptionConverter(de);
    }
}

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.j a  v a  2s.c o  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: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 . java 2  s  .c  om
    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:at.reppeitsolutions.formbuilder.components.pdf.itext.ITextSelect.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.setChoices(values);/*from  w  w  w.j  a va  2  s . co  m*/
    text.setFontSize(ITextInputText.FONTSIZE);
    text.setChoiceExports(text.getChoices());
    for (int i = 0; value != null && i < values.length; i++) {
        if (values[i].equals(value)) {
            text.setChoiceSelection(i);
            break;
        }
    }
    try {
        PdfFormField comboField = text.getComboField();
        if (locked) {
            comboField.setFieldFlags(BaseField.READ_ONLY);
        }
        writer.addAnnotation(comboField);
    } catch (IOException ex) {
        Logger.getLogger(ITextSelect.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(ITextSelect.class.getName()).log(Level.SEVERE, null, ex);
    }
}