/** * 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); }
protected PdfAppearance GetBorderAppearance() { PdfAppearance app = PdfAppearance.CreateAppearance(writer, box.Width, box.Height); switch (rotation) { case 90: app.SetMatrix(0, 1, -1, 0, box.Height, 0); break; case 180: app.SetMatrix(-1, 0, 0, -1, box.Width, box.Height); break; case 270: app.SetMatrix(0, -1, 1, 0, 0, box.Width); break; } app.SaveState(); // background if (backgroundColor != null) { app.SetColorFill(backgroundColor); app.Rectangle(0, 0, box.Width, box.Height); app.Fill(); } // border if (borderStyle == PdfBorderDictionary.STYLE_UNDERLINE) { if (borderWidth != 0 && borderColor != null) { app.SetColorStroke(borderColor); app.SetLineWidth(borderWidth); app.MoveTo(0, borderWidth / 2); app.LineTo(box.Width, borderWidth / 2); app.Stroke(); } } else if (borderStyle == PdfBorderDictionary.STYLE_BEVELED) { if (borderWidth != 0 && borderColor != null) { app.SetColorStroke(borderColor); app.SetLineWidth(borderWidth); app.Rectangle(borderWidth / 2, borderWidth / 2, box.Width - borderWidth, box.Height - borderWidth); app.Stroke(); } // beveled Color actual = backgroundColor; if (actual == null) { actual = Color.WHITE; } app.SetGrayFill(1); DrawTopFrame(app); app.SetColorFill(actual.Darker()); DrawBottomFrame(app); } else if (borderStyle == PdfBorderDictionary.STYLE_INSET) { if (borderWidth != 0 && borderColor != null) { app.SetColorStroke(borderColor); app.SetLineWidth(borderWidth); app.Rectangle(borderWidth / 2, borderWidth / 2, box.Width - borderWidth, box.Height - borderWidth); app.Stroke(); } // inset app.SetGrayFill(0.5f); DrawTopFrame(app); app.SetGrayFill(0.75f); DrawBottomFrame(app); } else { if (borderWidth != 0 && borderColor != null) { if (borderStyle == PdfBorderDictionary.STYLE_DASHED) { app.SetLineDash(3, 0); } app.SetColorStroke(borderColor); app.SetLineWidth(borderWidth); app.Rectangle(borderWidth / 2, borderWidth / 2, box.Width - borderWidth, box.Height - borderWidth); app.Stroke(); if ((options & COMB) != 0 && maxCharacterLength > 1) { float step = box.Width / maxCharacterLength; float yb = borderWidth / 2; float yt = box.Height - borderWidth / 2; for (int k = 1; k < maxCharacterLength; ++k) { float x = step * k; app.MoveTo(x, yb); app.LineTo(x, yt); } app.Stroke(); } } } app.RestoreState(); return(app); }