Package com.lowagie.text.pdf
Class RadioCheckField
java.lang.Object
com.lowagie.text.pdf.BaseField
com.lowagie.text.pdf.RadioCheckField
Creates a radio or a check field.
Example usage:
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("output.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
RadioCheckField bt = new RadioCheckField(writer, new Rectangle(100, 100, 200, 200), "radio", "v1");
bt.setCheckType(RadioCheckField.TYPE_CIRCLE);
bt.setBackgroundColor(Color.cyan);
bt.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
bt.setBorderColor(Color.red);
bt.setTextColor(Color.yellow);
bt.setBorderWidth(BaseField.BORDER_WIDTH_THICK);
bt.setChecked(false);
PdfFormField f1 = bt.getRadioField();
bt.setOnValue("v2");
bt.setChecked(true);
bt.setBox(new Rectangle(100, 300, 200, 400));
PdfFormField f2 = bt.getRadioField();
bt.setChecked(false);
PdfFormField top = bt.getRadioGroup(true, false);
bt.setOnValue("v3");
bt.setBox(new Rectangle(100, 500, 200, 600));
PdfFormField f3 = bt.getRadioField();
top.addKid(f1);
top.addKid(f2);
top.addKid(f3);
writer.addAnnotation(top);
bt = new RadioCheckField(writer, new Rectangle(300, 300, 400, 400), "check1", "Yes");
bt.setCheckType(RadioCheckField.TYPE_CHECK);
bt.setBorderWidth(BaseField.BORDER_WIDTH_THIN);
bt.setBorderColor(Color.black);
bt.setBackgroundColor(Color.white);
PdfFormField ck = bt.getCheckField();
writer.addAnnotation(ck);
document.close();
- Author:
- Paulo Soares (psoares@consiste.pt)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intA field with the symbol checkstatic final intA field with the symbol circlestatic final intA field with the symbol crossstatic final intA field with the symbol diamondstatic final intA field with the symbol squarestatic final intA field with the symbol starFields inherited from class com.lowagie.text.pdf.BaseField
alignment, backgroundColor, BORDER_WIDTH_MEDIUM, BORDER_WIDTH_THICK, BORDER_WIDTH_THIN, borderColor, borderStyle, borderWidth, box, COMB, DO_NOT_SCROLL, DO_NOT_SPELL_CHECK, EDIT, fieldName, FILE_SELECTION, font, fontSize, HIDDEN, HIDDEN_BUT_PRINTABLE, maxCharacterLength, MULTILINE, options, PASSWORD, READ_ONLY, REQUIRED, rotation, text, textColor, visibility, VISIBLE, VISIBLE_BUT_DOES_NOT_PRINT, writer -
Constructor Summary
ConstructorsConstructorDescriptionRadioCheckField(PdfWriter writer, Rectangle box, String fieldName, String onValue) Creates a new instance of RadioCheckField -
Method Summary
Modifier and TypeMethodDescriptiongetAppearance(boolean isRadio, boolean on) Gets the field appearance.getAppearanceRadioCircle(boolean on) Gets the special field appearance for the radio circle.Gets the check field.intGetter for property checkType.protected PdfFormFieldgetField(boolean isRadio) Gets a radio or check field.Getter for property onValue.Gets the radio field.getRadioGroup(boolean noToggleToOff, boolean radiosInUnison) Gets a radio group.booleanGetter for property checked.voidsetChecked(boolean checked) Sets the state of the field to checked or unchecked.voidsetCheckType(int checkType) Sets the checked symbol.voidsetOnValue(String onValue) Sets the value when the field is checked.Methods inherited from class com.lowagie.text.pdf.BaseField
breakLines, getAlignment, getBackgroundColor, getBorderAppearance, getBorderColor, getBorderStyle, getBorderWidth, getBox, getFieldName, getFont, getFontSize, getHardBreaks, getMaxCharacterLength, getOptions, getRealFont, getRotation, getText, getTextColor, getVisibility, getWriter, moveFields, setAlignment, setBackgroundColor, setBorderColor, setBorderStyle, setBorderWidth, setBox, setFieldName, setFont, setFontSize, setMaxCharacterLength, setOptions, setRotation, setRotationFromPage, setText, setTextColor, setVisibility, setWriter, trimRight
-
Field Details
-
TYPE_CHECK
public static final int TYPE_CHECKA field with the symbol check- See Also:
-
TYPE_CIRCLE
public static final int TYPE_CIRCLEA field with the symbol circle- See Also:
-
TYPE_CROSS
public static final int TYPE_CROSSA field with the symbol cross- See Also:
-
TYPE_DIAMOND
public static final int TYPE_DIAMONDA field with the symbol diamond- See Also:
-
TYPE_SQUARE
public static final int TYPE_SQUAREA field with the symbol square- See Also:
-
TYPE_STAR
public static final int TYPE_STARA field with the symbol star- See Also:
-
-
Constructor Details
-
RadioCheckField
Creates a new instance of RadioCheckField- Parameters:
writer- the documentPdfWriterbox- the field location and dimensionsfieldName- the field name. It must not benullonValue- the value when the field is checked
-
-
Method Details
-
getCheckType
public int getCheckType()Getter for property checkType.- Returns:
- Value of property checkType.
-
setCheckType
public void setCheckType(int checkType) Sets the checked symbol. It can beTYPE_CHECK,TYPE_CIRCLE,TYPE_CROSS,TYPE_DIAMOND,TYPE_SQUAREandTYPE_STAR.- Parameters:
checkType- the checked symbol
-
getOnValue
Getter for property onValue.- Returns:
- Value of property onValue.
-
setOnValue
Sets the value when the field is checked.- Parameters:
onValue- the value when the field is checked
-
isChecked
public boolean isChecked()Getter for property checked.- Returns:
- Value of property checked.
-
setChecked
public void setChecked(boolean checked) Sets the state of the field to checked or unchecked.- Parameters:
checked- the state of the field,truefor checked andfalsefor unchecked
-
getAppearance
public PdfAppearance getAppearance(boolean isRadio, boolean on) throws IOException, DocumentException Gets the field appearance.- Parameters:
isRadio-truefor a radio field andfalsefor a check fieldon-truefor the checked state,falseotherwise- Returns:
- the appearance
- Throws:
IOException- on errorDocumentException- on error
-
getAppearanceRadioCircle
Gets the special field appearance for the radio circle.- Parameters:
on-truefor the checked state,falseotherwise- Returns:
- the appearance
-
getRadioGroup
Gets a radio group. It's composed of the field specific keys, without the widget ones. This field is to be used as a field aggregator withaddKid().- Parameters:
noToggleToOff- iftrue, exactly one radio button must be selected at all times; clicking the currently selected button has no effect. Iffalse, clicking the selected button deselects it, leaving no button selected.radiosInUnison- iftrue, a group of radio buttons within a radio button field that use the same value for the on state will turn on and off in unison; that is if one is checked, they are all checked. Iffalse, the buttons are mutually exclusive (the same behavior as HTML radio buttons)- Returns:
- the radio group
-
getRadioField
Gets the radio field. It's only composed of the widget keys and must be used withgetRadioGroup(boolean,boolean).- Returns:
- the radio field
- Throws:
IOException- on errorDocumentException- on error
-
getCheckField
Gets the check field.- Returns:
- the check field
- Throws:
IOException- on errorDocumentException- on error
-
getField
Gets a radio or check field.- Parameters:
isRadio-trueto get a radio field,falseto get a check field- Returns:
- the field
- Throws:
IOException- on errorDocumentException- on error
-