Beispiel #1
0
        public PdfFormField AddCheckBox(string name, string value, bool status, float llx, float lly, float urx, float ury)
        {
            PdfFormField field = PdfFormField.CreateCheckBox(writer);

            SetCheckBoxParams(field, name, value, status, llx, lly, urx, ury);
            DrawCheckBoxAppearences(field, value, llx, lly, urx, ury);
            AddFormField(field);
            return(field);
        }
Beispiel #2
0
        /**
         * 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);
        }