/** * Gets the special field appearance for the radio circle. * @param on <CODE>true</CODE> for the checked state, <CODE>false</CODE> * otherwise * @return the appearance */ public PdfAppearance GetAppearanceRadioCircle(bool on) { 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; } Rectangle boxc = new Rectangle(app.BoundingBox); float cx = boxc.Width / 2; float cy = boxc.Height / 2; float r = (Math.Min(boxc.Width, boxc.Height) - borderWidth) / 2; if (r <= 0) { return(app); } if (backgroundColor != null) { app.SetColorFill(backgroundColor); app.Circle(cx, cy, r + borderWidth / 2); app.Fill(); } if (borderWidth > 0 && borderColor != null) { app.SetLineWidth(borderWidth); app.SetColorStroke(borderColor); app.Circle(cx, cy, r); app.Stroke(); } if (on) { if (textColor == null) { app.ResetGrayFill(); } else { app.SetColorFill(textColor); } app.Circle(cx, cy, r / 2); app.Fill(); } return(app); }
public void DrawRadioAppearences(PdfFormField field, string value, float llx, float lly, float urx, float ury) { PdfAppearance tpOn = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly); tpOn.DrawRadioField(0f, 0f, urx - llx, ury - lly, true); field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, value, tpOn); PdfAppearance tpOff = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly); tpOff.DrawRadioField(0f, 0f, urx - llx, ury - lly, false); field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff); }
public PdfFormField AddMap(string name, string value, string url, PdfContentByte appearance, float llx, float lly, float urx, float ury) { PdfAction action = PdfAction.CreateSubmitForm(url, null, PdfAction.SUBMIT_HTML_FORMAT | PdfAction.SUBMIT_COORDINATES); PdfFormField button = new PdfFormField(writer, llx, lly, urx, ury, action); SetButtonParams(button, PdfFormField.FF_PUSHBUTTON, name, null); PdfAppearance pa = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly); pa.Add(appearance); button.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, pa); AddFormField(button); return(button); }
/** * @param field * @param llx * @param lly * @param urx * @param ury */ public void DrawSignatureAppearences(PdfFormField field, float llx, float lly, float urx, float ury) { PdfAppearance tp = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly); tp.SetGrayFill(1.0f); tp.Rectangle(0, 0, urx - llx, ury - lly); tp.Fill(); tp.SetGrayStroke(0); tp.SetLineWidth(1); tp.Rectangle(0.5f, 0.5f, urx - llx - 0.5f, ury - lly - 0.5f); tp.ClosePathStroke(); tp.SaveState(); tp.Rectangle(1, 1, urx - llx - 2, ury - lly - 2); tp.Clip(); tp.NewPath(); tp.RestoreState(); field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp); }
public void DrawCheckBoxAppearences(PdfFormField field, string value, float llx, float lly, float urx, float ury) { BaseFont font = BaseFont.CreateFont(BaseFont.ZAPFDINGBATS, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); float size = (ury - lly); PdfAppearance tpOn = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly); PdfAppearance tp2 = (PdfAppearance)tpOn.Duplicate; tp2.SetFontAndSize(font, size); tp2.ResetRGBColorFill(); field.DefaultAppearanceString = tp2; tpOn.DrawTextField(0f, 0f, urx - llx, ury - lly); tpOn.SaveState(); tpOn.ResetRGBColorFill(); tpOn.BeginText(); tpOn.SetFontAndSize(font, size); tpOn.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "4", (urx - llx) / 2, (ury - lly) / 2 - (size * 0.3f), 0); tpOn.EndText(); tpOn.RestoreState(); field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, value, tpOn); PdfAppearance tpOff = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly); tpOff.DrawTextField(0f, 0f, urx - llx, ury - lly); field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff); }
public void DrawSingleLineOfText(PdfFormField field, string text, BaseFont font, float fontSize, float llx, float lly, float urx, float ury) { PdfAppearance tp = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly); PdfAppearance tp2 = (PdfAppearance)tp.Duplicate; tp2.SetFontAndSize(font, fontSize); tp2.ResetRGBColorFill(); field.DefaultAppearanceString = tp2; tp.DrawTextField(0f, 0f, urx - llx, ury - lly); tp.BeginVariableText(); tp.SaveState(); tp.Rectangle(3f, 3f, urx - llx - 6f, ury - lly - 6f); tp.Clip(); tp.NewPath(); tp.BeginText(); tp.SetFontAndSize(font, fontSize); tp.ResetRGBColorFill(); tp.SetTextMatrix(4, (ury - lly) / 2 - (fontSize * 0.3f)); tp.ShowText(text); tp.EndText(); tp.RestoreState(); tp.EndVariableText(); field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp); }
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); }