protected static PdfFormField CreateChoice(PdfWriter writer, int flags, PdfArray options, int topIndex) { PdfFormField field = new PdfFormField(writer); field.Put(PdfName.FT, PdfName.CH); field.Put(PdfName.FF, new PdfNumber(flags)); field.Put(PdfName.OPT, options); if (topIndex > 0) { field.Put(PdfName.TI, new PdfNumber(topIndex)); } return(field); }
public static PdfFormField CreateTextField(PdfWriter writer, bool multiline, bool password, int maxLen) { PdfFormField field = new PdfFormField(writer); field.Put(PdfName.FT, PdfName.TX); int flags = (multiline ? FF_MULTILINE : 0); flags += (password ? FF_PASSWORD : 0); field.Put(PdfName.FF, new PdfNumber(flags)); if (maxLen > 0) { field.Put(PdfName.MAXLEN, new PdfNumber(maxLen)); } return(field); }
public static PdfFormField CreateSignature(PdfWriter writer) { PdfFormField field = new PdfFormField(writer); field.Put(PdfName.FT, PdfName.SIG); return(field); }
protected PdfFormField GetChoiceField(bool isList) { options &= (~MULTILINE) & (~COMB); String[] uchoices = choices; if (uchoices == null) { uchoices = new String[0]; } int topChoice = choiceSelection; if (topChoice >= uchoices.Length) { topChoice = uchoices.Length - 1; } if (text == null) { text = ""; //fixed by Kazuya Ujihara (ujihara.jp) } if (topChoice >= 0) { text = uchoices[topChoice]; } if (topChoice < 0) { topChoice = 0; } PdfFormField field = null; String[,] mix = null; if (choiceExports == null) { if (isList) { field = PdfFormField.CreateList(writer, uchoices, topChoice); } else { field = PdfFormField.CreateCombo(writer, (options & EDIT) != 0, uchoices, topChoice); } } else { mix = new String[uchoices.Length, 2]; for (int k = 0; k < mix.GetLength(0); ++k) { mix[k, 0] = mix[k, 1] = uchoices[k]; } int top = Math.Min(uchoices.Length, choiceExports.Length); for (int k = 0; k < top; ++k) { if (choiceExports[k] != null) { mix[k, 0] = choiceExports[k]; } } if (isList) { field = PdfFormField.CreateList(writer, mix, topChoice); } else { field = PdfFormField.CreateCombo(writer, (options & EDIT) != 0, mix, topChoice); } } field.SetWidget(box, PdfAnnotation.HIGHLIGHT_INVERT); if (rotation != 0) { field.MKRotation = rotation; } if (fieldName != null) { field.FieldName = fieldName; if (uchoices.Length > 0) { if (mix != null) { field.ValueAsString = mix[topChoice, 0]; field.DefaultValueAsString = mix[topChoice, 0]; } else { field.ValueAsString = text; field.DefaultValueAsString = text; } } if ((options & READ_ONLY) != 0) { field.SetFieldFlags(PdfFormField.FF_READ_ONLY); } if ((options & REQUIRED) != 0) { field.SetFieldFlags(PdfFormField.FF_REQUIRED); } if ((options & DO_NOT_SPELL_CHECK) != 0) { field.SetFieldFlags(PdfFormField.FF_DONOTSPELLCHECK); } } field.BorderStyle = new PdfBorderDictionary(borderWidth, borderStyle, new PdfDashPattern(3)); PdfAppearance tp; if (isList) { tp = GetListAppearance(); if (topFirst > 0) { field.Put(PdfName.TI, new PdfNumber(topFirst)); } } else { tp = GetAppearance(); } field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp); PdfAppearance da = (PdfAppearance)tp.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); }