bookmarks property

PdfBookmarkBase get bookmarks

Gets the bookmark collection of the document.

//Create a new document.
PdfDocument document = PdfDocument();
//Create document bookmarks.
document.bookmarks.add('Interactive Feature')
  ..destination = PdfDestination(document.pages.add(), Offset(20, 20))
  ..textStyle = [PdfTextStyle.bold]
  ..color = PdfColor(255, 0, 0);
//Save the document.
List<int> bytes = await document.save();
//Dispose the document.
document.dispose();

Implementation

PdfBookmarkBase get bookmarks {
  if (_helper.isLoadedDocument) {
    if (_bookmark == null) {
      if (_helper.catalog.containsKey(PdfDictionaryProperties.outlines)) {
        final IPdfPrimitive? outlines = PdfCrossTable.dereference(
            _helper.catalog[PdfDictionaryProperties.outlines]);
        if (outlines != null && outlines is PdfDictionary) {
          _bookmark =
              PdfBookmarkBaseHelper.loaded(outlines, _helper.crossTable);
          PdfBookmarkBaseHelper.getHelper(_bookmark!).reproduceTree();
        } else {
          _bookmark = _createBookmarkRoot();
        }
      } else {
        _bookmark = _createBookmarkRoot();
      }
    }
    return _bookmark!;
  } else {
    if (_outlines == null) {
      _outlines = PdfBookmarkBaseHelper.loadInternal();
      _helper.catalog[PdfDictionaryProperties.outlines] =
          PdfReferenceHolder(_outlines);
    }
    return _outlines!;
  }
}