text property

String get text

Gets or sets the text in the text box.

Implementation

String get text {
  if (_helper.isLoadedField) {
    IPdfPrimitive? str;
    final IPdfPrimitive? referenceHolder =
        _helper.dictionary![PdfDictionaryProperties.v];
    if (referenceHolder != null && referenceHolder is PdfReferenceHolder) {
      final IPdfPrimitive? textObject =
          PdfCrossTable.dereference(referenceHolder);
      if (textObject is PdfStream) {
        final PdfStream stream = referenceHolder.object! as PdfStream;
        stream.decompress();
        final List<int> bytes = stream.dataStream!;
        final String data = utf8.decode(bytes);
        str = PdfString(data);
      } else if (textObject is PdfString) {
        str = PdfFieldHelper.getValue(_helper.dictionary!, _helper.crossTable,
            PdfDictionaryProperties.v, true);
      } else {
        str = PdfString('');
      }
    } else {
      str = PdfFieldHelper.getValue(_helper.dictionary!, _helper.crossTable,
          PdfDictionaryProperties.v, true);
    }
    _text = str != null && str is PdfString ? str.value : '';
    return _text!;
  }
  return _text!;
}
set text (String value)

Implementation

set text(String value) {
  if (_helper.isLoadedField) {
    //check if not readOnly.
    if (!_helper.isFlagPresent(FieldFlags.readOnly)) {
      _helper.isTextChanged = true;
      if (_helper.dictionary!.containsKey(PdfDictionaryProperties.aa)) {
        final IPdfPrimitive? dic =
            _helper.dictionary![PdfDictionaryProperties.aa];
        if (dic != null && dic is PdfDictionary) {
          final IPdfPrimitive? dicRef = dic[PdfDictionaryProperties.k];
          if (dicRef != null && dicRef is PdfReferenceHolder) {
            final IPdfPrimitive? dict = dicRef.object;
            if (dict != null && dict is PdfDictionary) {
              final IPdfPrimitive? str =
                  PdfCrossTable.dereference(dict['JS']);
              if (str != null && str is PdfString) {
                _helper.dictionary!.setProperty(
                    PdfDictionaryProperties.v, PdfString(str.value!));
              }
            }
          }
        }
      }
      _helper.dictionary!
          .setProperty(PdfDictionaryProperties.v, PdfString(value));
      _helper.changed = true;
      PdfFormHelper.getHelper(super.form!).setAppearanceDictionary = true;
      if (PdfFormHelper.getHelper(super.form!).isUR3) {
        _helper.dictionary!.beginSaveList ??= <SavePdfPrimitiveCallback>[];
        _helper.dictionary!.beginSaveList!.add(_dictSave);
      }
    } else {
      _helper.changed = false;
    }
  } else {
    if (_text != value) {
      _text = value;
      _helper.dictionary!.setString(PdfDictionaryProperties.v, _text);
    }
  }
}