CreateCombo() public static method

public static CreateCombo ( PdfWriter writer, bool edit, String options, int topIndex ) : PdfFormField
writer PdfWriter
edit bool
options String
topIndex int
return PdfFormField
Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        protected PdfFormField GetChoiceField(bool isList)
        {
            options &= (~MULTILINE) & (~COMB);
            String[] uchoices = choices;
            if (uchoices == null)
            {
                uchoices = new String[0];
            }
            int topChoice = GetTopChoice();

            if (uchoices.Length > topChoice)
            {
                text = uchoices[topChoice];
            }

            if (text == null)
            {
                text = "";
            }

            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)
                    {
                        if (choiceSelections.Count < 2)
                        {
                            field.ValueAsString        = mix[topChoice, 0];
                            field.DefaultValueAsString = mix[topChoice, 0];
                        }
                        else
                        {
                            WriteMultipleValues(field, mix);
                        }
                    }
                    else
                    {
                        if (choiceSelections.Count < 2)
                        {
                            field.ValueAsString        = text;
                            field.DefaultValueAsString = text;
                        }
                        else
                        {
                            WriteMultipleValues(field, null);
                        }
                    }
                }
                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);
                }
                if ((options & MULTISELECT) != 0)
                {
                    field.SetFieldFlags(PdfFormField.FF_MULTISELECT);
                }
            }
            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);
        }
        protected PdfFormField GetChoiceField(bool isList)
        {
            options &= (~MULTILINE) & (~COMB);
            var uchoices = Choices;

            if (uchoices == null)
            {
                uchoices = new string[0];
            }

            var 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 (var k = 0; k < mix.GetLength(0); ++k)
                {
                    mix[k, 0] = mix[k, 1] = uchoices[k];
                }

                var top = Math.Min(uchoices.Length, ChoiceExports.Length);
                for (var 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.HighlightInvert);
            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.AppearanceNormal, tp);
            var 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);
        }