insert method

PdfBookmark insert(
  1. int index,
  2. String title
)

Inserts a new outline at the specified index.

//Create a new document.
PdfDocument document = PdfDocument();
//Insert bookmark at specified index
document.bookmarks.insert(0, 'bookmark')
  ..destination = PdfDestination(document.pages.add(), Offset(20, 20));
//Save the document.
List<int> bytes = await document.save();
//Dispose the document.
document.dispose();

Implementation

PdfBookmark insert(int index, String title) {
  if (index < 0 || index > count) {
    throw RangeError.value(index);
  }
  PdfBookmark outline;
  if (index == count) {
    outline = add(title);
  } else {
    final PdfBookmark next = this[index];
    final PdfBookmark? prevoius = (index == 0) ? null : this[index - 1];
    outline = PdfBookmark._internal(title, this, prevoius, next);
    _list.insert(index, outline);
    if (prevoius != null) {
      prevoius._next = outline;
    }
    next._previous = outline;
    _updateFields();
  }
  return outline;
}