Aspose::Words::Saving::BookmarksOutlineLevelCollection class
Contents
[
Hide
]BookmarksOutlineLevelCollection class
A collection of individual bookmarks outline level. To learn more, visit the Working with Bookmarks documentation article.
class BookmarksOutlineLevelCollection : public System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<System::String, int32_t>>
Methods
Method | Description |
---|---|
Add(const System::String&, int32_t) | Adds a bookmark to the collection. |
begin() | |
begin() const | |
BookmarksOutlineLevelCollection() | |
cbegin() const | |
cend() const | |
Clear() | Removes all elements from the collection. |
Contains(const System::String&) | Determines whether the collection contains a bookmark with the given name. |
end() | |
end() const | |
get_Count() | Gets the number of elements contained in the collection. |
GetEnumerator() override | Returns an enumerator object that can be used to iterate over all items in the collection. |
GetType() const override | |
idx_get(const System::String&) | Gets or a sets a bookmark outline level by the bookmark name. |
idx_get(int32_t) | Gets or sets a bookmark outline level at the specified index. |
idx_set(const System::String&, int32_t) | Gets or a sets a bookmark outline level by the bookmark name. |
idx_set(int32_t, int32_t) | Gets or sets a bookmark outline level at the specified index. |
IndexOfKey(const System::String&) | Returns the zero-based index of the specified bookmark in the collection. |
Is(const System::TypeInfo&) const override | |
Remove(const System::String&) | Removes a bookmark with the specified name from the collection. |
RemoveAt(int32_t) | Removes a bookmark at the specified index. |
static Type() | |
virtualizeBeginConstIterator() const override | |
virtualizeBeginIterator() override | |
virtualizeEndConstIterator() const override | |
virtualizeEndIterator() override |
Typedefs
Typedef | Description |
---|---|
const_iterator | |
iterator | |
iterator_holder_type | |
virtualized_iterator | |
virtualized_iterator_element |
Remarks
Key is a case-insensitive string bookmark name. Value is a int bookmark outline level.
Bookmark outline level may be a value from 0 to 9. Specify 0 and Word bookmark will not be displayed in the document outline. Specify 1 and Word bookmark will be displayed in the document outline at level 1; 2 for level 2 and so on.
Examples
Shows how to set outline levels for bookmarks.
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a bookmark with another bookmark nested inside it.
builder->StartBookmark(u"Bookmark 1");
builder->Writeln(u"Text inside Bookmark 1.");
builder->StartBookmark(u"Bookmark 2");
builder->Writeln(u"Text inside Bookmark 1 and 2.");
builder->EndBookmark(u"Bookmark 2");
builder->Writeln(u"Text inside Bookmark 1.");
builder->EndBookmark(u"Bookmark 1");
// Insert another bookmark.
builder->StartBookmark(u"Bookmark 3");
builder->Writeln(u"Text inside Bookmark 3.");
builder->EndBookmark(u"Bookmark 3");
// When saving to .pdf, bookmarks can be accessed via a drop-down menu and used as anchors by most readers.
// Bookmarks can also have numeric values for outline levels,
// enabling lower level outline entries to hide higher-level child entries when collapsed in the reader.
auto pdfSaveOptions = MakeObject<PdfSaveOptions>();
SharedPtr<BookmarksOutlineLevelCollection> outlineLevels = pdfSaveOptions->get_OutlineOptions()->get_BookmarksOutlineLevels();
outlineLevels->Add(u"Bookmark 1", 1);
outlineLevels->Add(u"Bookmark 2", 2);
outlineLevels->Add(u"Bookmark 3", 3);
ASSERT_EQ(3, outlineLevels->get_Count());
ASSERT_TRUE(outlineLevels->Contains(u"Bookmark 1"));
ASSERT_EQ(1, outlineLevels->idx_get(0));
ASSERT_EQ(2, outlineLevels->idx_get(u"Bookmark 2"));
ASSERT_EQ(2, outlineLevels->IndexOfKey(u"Bookmark 3"));
// We can remove two elements so that only the outline level designation for "Bookmark 1" is left.
outlineLevels->RemoveAt(2);
outlineLevels->Remove(u"Bookmark 2");
// There are nine outline levels. Their numbering will be optimized during the save operation.
// In this case, levels "5" and "9" will become "2" and "3".
outlineLevels->Add(u"Bookmark 2", 5);
outlineLevels->Add(u"Bookmark 3", 9);
doc->Save(ArtifactsDir + u"BookmarksOutlineLevelCollection.BookmarkLevels.pdf", pdfSaveOptions);
// Emptying this collection will preserve the bookmarks and put them all on the same outline level.
outlineLevels->Clear();
See Also
- Namespace Aspose::Words::Saving
- Library Aspose.Words for C++