iTextSharp.text.pdf.TextField.GetTextField C# (CSharp) Метод

GetTextField() публичный Метод

public GetTextField ( ) : PdfFormField
Результат PdfFormField
        public PdfFormField GetTextField() {
            if (maxCharacterLength <= 0)
                options &= ~COMB;
            if ((options & COMB) != 0)
                options &= ~MULTILINE;
            PdfFormField field = PdfFormField.CreateTextField(writer, false, false, maxCharacterLength);
            field.SetWidget(box, PdfAnnotation.HIGHLIGHT_INVERT);
            switch (alignment) {
                case Element.ALIGN_CENTER:
                    field.Quadding = PdfFormField.Q_CENTER;
                    break;
                case Element.ALIGN_RIGHT:
                    field.Quadding = PdfFormField.Q_RIGHT;
                    break;
            }
            if (rotation != 0)
                field.MKRotation = rotation;
            if (fieldName != null) {
                field.FieldName = fieldName;
                if (!"".Equals(text))
                    field.ValueAsString = text;
                if (defaultText != null)
                    field.DefaultValueAsString = defaultText;
                if ((options & READ_ONLY) != 0)
                    field.SetFieldFlags(PdfFormField.FF_READ_ONLY);
                if ((options & REQUIRED) != 0)
                    field.SetFieldFlags(PdfFormField.FF_REQUIRED);
                if ((options & MULTILINE) != 0)
                    field.SetFieldFlags(PdfFormField.FF_MULTILINE);
                if ((options & DO_NOT_SCROLL) != 0)
                    field.SetFieldFlags(PdfFormField.FF_DONOTSCROLL);
                if ((options & PASSWORD) != 0)
                    field.SetFieldFlags(PdfFormField.FF_PASSWORD);
                if ((options & FILE_SELECTION) != 0)
                    field.SetFieldFlags(PdfFormField.FF_FILESELECT);
                if ((options & DO_NOT_SPELL_CHECK) != 0)
                    field.SetFieldFlags(PdfFormField.FF_DONOTSPELLCHECK);
                if ((options & COMB) != 0)
                    field.SetFieldFlags(PdfFormField.FF_COMB);
            }
            field.BorderStyle = new PdfBorderDictionary(borderWidth, borderStyle, new PdfDashPattern(3));
            PdfAppearance 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;
        }
        

Usage Example

Пример #1
1
// ---------------------------------------------------------------------------
    /**
     * Show keys and values passed to the query string with GET
     */    
    protected void DoGet(byte[] pdf, Stream stream) {
      // We get a resource from our web app
      PdfReader reader = new PdfReader(pdf);
      // Now we create the PDF
      using (PdfStamper stamper = new PdfStamper(reader, stream)) {
        // We add a submit button to the existing form
        PushbuttonField button = new PushbuttonField(
          stamper.Writer, new Rectangle(90, 660, 140, 690), "submit"
        );
        button.Text = "POST";
        button.BackgroundColor = new GrayColor(0.7f);
        button.Visibility = PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT;
        PdfFormField submit = button.Field;
        submit.Action = PdfAction.CreateSubmitForm(
          WebContext.Request.RawUrl, null, 0
        );
        stamper.AddAnnotation(submit, 1);
        // We add an extra field that can be used to upload a file
        TextField file = new TextField(
          stamper.Writer, new Rectangle(160, 660, 470, 690), "image"
        );
        file.Options = TextField.FILE_SELECTION;
        file.BackgroundColor = new GrayColor(0.9f);
        PdfFormField upload = file.GetTextField();
        upload.SetAdditionalActions(PdfName.U,
          PdfAction.JavaScript(
            "this.getField('image').browseForFileToSubmit();"
            + "this.getField('submit').setFocus();",
            stamper.Writer
          )
        );
        stamper.AddAnnotation(upload, 1);
      }
    }
All Usage Examples Of iTextSharp.text.pdf.TextField::GetTextField