public PdfFormField AddHiddenField(string name, string value) { PdfFormField hidden = PdfFormField.CreateEmpty(writer); hidden.FieldName = name; hidden.ValueAsName = value; AddFormField(hidden); return(hidden); }
public PdfFormField AddRadioButton(PdfFormField radiogroup, string value, float llx, float lly, float urx, float ury) { PdfFormField radio = PdfFormField.CreateEmpty(writer); radio.SetWidget(new Rectangle(llx, lly, urx, ury), PdfAnnotation.HIGHLIGHT_TOGGLE); string name = ((PdfName)radiogroup.Get(PdfName.V)).ToString().Substring(1); if (name.Equals(value)) { radio.AppearanceState = value; } else { radio.AppearanceState = "Off"; } DrawRadioAppearences(radio, value, llx, lly, urx, ury); radiogroup.AddKid(radio); return(radio); }
/** * Gets a radio or check field. * @param isRadio <CODE>true</CODE> to get a radio field, <CODE>false</CODE> to get * a check field * @throws IOException on error * @throws DocumentException on error * @return the field */ protected PdfFormField GetField(bool isRadio) { PdfFormField field = null; if (isRadio) { field = PdfFormField.CreateEmpty(writer); } else { field = PdfFormField.CreateCheckBox(writer); } field.SetWidget(box, PdfAnnotation.HIGHLIGHT_INVERT); if (!isRadio) { field.FieldName = fieldName; if ((options & READ_ONLY) != 0) { field.SetFieldFlags(PdfFormField.FF_READ_ONLY); } if ((options & REQUIRED) != 0) { field.SetFieldFlags(PdfFormField.FF_REQUIRED); } field.ValueAsName = vchecked ? onValue : "Off"; } if (text != null) { field.MKNormalCaption = text; } if (rotation != 0) { field.MKRotation = rotation; } field.BorderStyle = new PdfBorderDictionary(borderWidth, borderStyle, new PdfDashPattern(3)); PdfAppearance tpon = GetAppearance(isRadio, true); PdfAppearance tpoff = GetAppearance(isRadio, false); field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, onValue, tpon); field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpoff); field.AppearanceState = vchecked ? onValue : "Off"; PdfAppearance da = (PdfAppearance)tpon.Duplicate; da.SetFontAndSize(RealFont, fontSize); if (textColor == null) { da.SetGrayFill(0); } else { da.SetColorFill(textColor); } field.DefaultAppearanceString = da; if (borderColor != null) { field.MKBorderColor = borderColor; } if (backgroundColor != null) { field.MKBackgroundColor = backgroundColor; } switch (visibility) { case HIDDEN: field.Flags = PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_HIDDEN; break; case VISIBLE_BUT_DOES_NOT_PRINT: break; case HIDDEN_BUT_PRINTABLE: field.Flags = PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_NOVIEW; break; default: field.Flags = PdfAnnotation.FLAGS_PRINT; break; } return(field); }