public class RadioCheckField extends BaseField
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();
| Modifier and Type | Field and Description |
|---|---|
static int |
TYPE_CHECK
A field with the symbol check
|
static int |
TYPE_CIRCLE
A field with the symbol circle
|
static int |
TYPE_CROSS
A field with the symbol cross
|
static int |
TYPE_DIAMOND
A field with the symbol diamond
|
static int |
TYPE_SQUARE
A field with the symbol square
|
static int |
TYPE_STAR
A field with the symbol star
|
alignment, alternateFieldName, 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, INVISIBLE, LOCKED, mappingName, maxCharacterLength, MULTILINE, MULTISELECT, NOVIEW, options, PASSWORD, PRINT, READ_ONLY, REQUIRED, rotation, text, textColor, visibility, VISIBLE, VISIBLE_BUT_DOES_NOT_PRINT, writer| Constructor and Description |
|---|
RadioCheckField(PdfWriter writer,
Rectangle box,
String fieldName,
String onValue)
Creates a new instance of RadioCheckField
|
RadioCheckField(PdfWriter writer,
String fieldName,
String onValue)
Creates a new instance of parent RadioCheckField with the default appearance of type 'cross'
|
| Modifier and Type | Method and Description |
|---|---|
static PdfAppearance |
getAppearance(boolean on,
PdfWriter writer,
int checkType,
int rotation,
int borderStyle,
Rectangle box,
float borderWidth,
float fontSize,
String text,
Color textColor,
Color backgroundColor,
Color borderColor,
BaseFont ufont)
Gets the field appearance.
|
static PdfAppearance |
getAppearanceRadioCircle(boolean on,
PdfWriter writer,
Rectangle box,
int rotation,
Color backgroundColor,
float borderWidth,
Color borderColor,
Color textColor)
Gets the special field appearance for the radio circle.
|
static PdfAppearance |
getAppearanceRadioCross(boolean on,
PdfWriter writer,
Rectangle box,
int rotation,
Color backgroundColor,
float borderWidth,
Color borderColor,
Color textColor)
Gets the special field appearance for the radio circle.
|
PdfFormField |
getCheckboxParent()
Gets a parent of a checkbox autofill parent.
|
PdfFormField |
getCheckField()
Deprecated.
use
getFullField() instead |
int |
getCheckType()
Getter for property checkType.
|
protected PdfFormField |
getField(boolean isKid)
Gets a radio or check field.
|
PdfFormField |
getFullField()
Gets the full parent field (There are no kids) This is the case for non-autofill fields and non-radiobutton
fields
|
PdfFormField |
getKidField()
Gets the child field.
|
String |
getOnValue()
Getter for property onValue.
|
PdfFormField |
getRadioField()
Deprecated.
use
getKidField() instead |
PdfFormField |
getRadioGroup(boolean noToggleToOff,
boolean radiosInUnison)
Gets a radio group.
|
boolean |
isChecked()
Getter for property checked.
|
void |
setChecked(boolean checked)
Sets the state of the field to checked or unchecked.
|
void |
setCheckType(int checkType)
Sets the checked symbol.
|
void |
setOnValue(String onValue)
Sets the value when the field is checked.
|
breakLines, breakLines, getAlignment, getAllHardBreaks, getAlternateFieldName, getBackgroundColor, getBorderAppearance, getBorderColor, getBorderStyle, getBorderWidth, getBox, getFieldName, getFont, getFontSize, getHardBreaks, getMappingName, getMaxCharacterLength, getOptions, getRealFont, getRotation, getText, getTextColor, getVisibility, getWriter, moveFields, setAlignment, setAlternateFieldName, setBackgroundColor, setBorderColor, setBorderStyle, setBorderWidth, setBox, setFieldName, setFont, setFontSize, setMappingName, setMaxCharacterLength, setOptions, setRotation, setRotationFromPage, setText, setTextColor, setVisibility, setWriter, trimRightpublic static final int TYPE_CHECK
public static final int TYPE_CIRCLE
public static final int TYPE_CROSS
public static final int TYPE_DIAMOND
public static final int TYPE_SQUARE
public static final int TYPE_STAR
public RadioCheckField(PdfWriter writer, Rectangle box, String fieldName, String onValue)
writer - the document PdfWriterbox - the field location and dimensionsfieldName - the field name. It must not be nullonValue - the value when the field is checkedpublic RadioCheckField(PdfWriter writer, String fieldName, String onValue)
writer - the document PdfWriterfieldName - the field name. It must not be nullonValue - the value when the field is checkedpublic static PdfAppearance getAppearance(boolean on, PdfWriter writer, int checkType, int rotation, int borderStyle, Rectangle box, float borderWidth, float fontSize, String text, Color textColor, Color backgroundColor, Color borderColor, BaseFont ufont)
For Circle and Cross own appearances are drawn. For all other styles the ZapfDingbats font it used.
public static PdfAppearance getAppearanceRadioCircle(boolean on, PdfWriter writer, Rectangle box, int rotation, Color backgroundColor, float borderWidth, Color borderColor, Color textColor)
on - true for the checked state otherwise, falsepublic static PdfAppearance getAppearanceRadioCross(boolean on, PdfWriter writer, Rectangle box, int rotation, Color backgroundColor, float borderWidth, Color borderColor, Color textColor)
on - true for the checked state, false
otherwisepublic int getCheckType()
public void setCheckType(int checkType)
TYPE_CHECK,
TYPE_CIRCLE,
TYPE_CROSS,
TYPE_DIAMOND,
TYPE_SQUARE and
TYPE_STAR.checkType - the checked symbolpublic String getOnValue()
public void setOnValue(String onValue)
onValue - the value when the field is checkedpublic boolean isChecked()
public void setChecked(boolean checked)
checked - the state of the field, true for checked and false for uncheckedpublic PdfFormField getRadioGroup(boolean noToggleToOff, boolean radiosInUnison)
addKid().noToggleToOff - if true, exactly one radio button must be selected at all times; clicking the
currently selected button has no effect. If false, clicking the selected
button deselects it, leaving no button selected.radiosInUnison - if true, 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. If false, the buttons are mutually exclusive (the same
behavior as HTML radio buttons)@Deprecated public PdfFormField getRadioField() throws IOException, DocumentException
getKidField() insteadgetRadioGroup(boolean, boolean).IOException - on errorDocumentException - on error@Deprecated public PdfFormField getCheckField() throws IOException, DocumentException
getFullField() insteadIOException - on errorDocumentException - on errorpublic PdfFormField getCheckboxParent()
addKid().public PdfFormField getKidField() throws IOException, DocumentException
getRadioGroup(boolean, boolean) or getCheckboxParent().IOException - on errorDocumentException - on errorpublic PdfFormField getFullField() throws IOException, DocumentException
IOException - on errorDocumentException - on errorprotected PdfFormField getField(boolean isKid) throws IOException, DocumentException
isKid - true to get a child field, false to get full parent fieldIOException - on errorDocumentException - on errorCopyright © 2024. All rights reserved.