addTextBox method

Future<bool> addTextBox(
  1. int pageIndex,
  2. Offset devicePoint,
  3. String contents, {
  4. double width = 200,
  5. double height = 60,
})

Implementation

Future<bool> addTextBox(int pageIndex, Offset devicePoint, String contents, {double width = 200, double height = 60}) async {
  attach();
  final UPdfEdit? edit = _edit;
  if (edit == null) return false;
  final UDocPageInfo info = viewer.pageInfo(pageIndex);
  final Offset origin = devicePointToPdf(info, devicePoint);
  final int number = await edit.addAnnotation(
    pageIndex,
    UPdfAnnotationSpec(
      style: UPdfAnnotationStyle.freeText,
      rect: Rect.fromLTWH(origin.dx, origin.dy - height, width, height),
      color: const Color(0x00FFFFFF),
      borderColor: _inkColor,
      borderWidth: 1,
      contents: contents,
      fontSize: _fontSize,
      author: _author,
      rtl: UDocText.isRtl(contents),
    ),
  );
  if (number > 0) _undoStack.add(number);
  viewer.invalidatePage(pageIndex);
  notifyListeners();
  return number > 0;
}