public PdfFormField AddComboBox(string name, string[] options, string defaultValue, bool editable, BaseFont font, float fontSize, float llx, float lly, float urx, float ury) { PdfFormField choice = PdfFormField.CreateCombo(writer, editable, options, 0); SetChoiceParams(choice, name, defaultValue, llx, lly, urx, ury); if (defaultValue == null) { defaultValue = options[0]; } DrawSingleLineOfText(choice, defaultValue, font, fontSize, llx, lly, urx, ury); AddFormField(choice); return(choice); }
public PdfFormField AddComboBox(string name, string[,] options, string defaultValue, bool editable, BaseFont font, float fontSize, float llx, float lly, float urx, float ury) { PdfFormField choice = PdfFormField.CreateCombo(writer, editable, options, 0); SetChoiceParams(choice, name, defaultValue, llx, lly, urx, ury); string value = null; for (int i = 0; i < options.GetLength(0); i++) { if (options[i, 0].Equals(defaultValue)) { value = options[i, 1]; break; } } if (value == null) { value = options[0, 1]; } DrawSingleLineOfText(choice, value, font, fontSize, llx, lly, urx, ury); AddFormField(choice); return(choice); }
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); }