Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/c6b5dde772d239f66bb02be882a76693 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/c6b5dde772d239f66bb02be882a76693 to your computer and use it in GitHub Desktop.
Working with Bookmarks in PDF Files using C++
Working with Bookmarks in PDF Files using C++
// Create an instance of the PdfBookmarkEditor class
System::SharedPtr<Aspose::Pdf::Facades::PdfBookmarkEditor> editor = System::MakeObject<Aspose::Pdf::Facades::PdfBookmarkEditor>();
// Load the PDF document
editor->BindPdf(u"SourceDirectory\\Sample 1.pdf");
// Create the Bookmark
editor->CreateBookmarkOfPage(u"Bookmark for page 1", 1);
// Save the PDF document
editor->Save(u"OutputDirectory\\AddBookmark_out.pdf");
// Create an instance of the PdfBookmarkEditor class
System::SharedPtr<Aspose::Pdf::Facades::PdfBookmarkEditor> editor = System::MakeObject<Aspose::Pdf::Facades::PdfBookmarkEditor>();
// Load the PDF document
editor->BindPdf(u"SourceDirectory\\Sample 1.pdf");
// Create 1st Child Bookmark
System::SharedPtr<Aspose::Pdf::Facades::Bookmark> bm1 = System::MakeObject<Aspose::Pdf::Facades::Bookmark>();
bm1->set_PageNumber(1);
bm1->set_Title(u"First child");
// Create 2nd Child Bookmark
System::SharedPtr<Aspose::Pdf::Facades::Bookmark> bm2 = System::MakeObject<Aspose::Pdf::Facades::Bookmark>();
bm2->set_PageNumber(2);
bm2->set_Title(u"Second child");
// Create Parent Bookmark
System::SharedPtr<Aspose::Pdf::Facades::Bookmark> bm = System::MakeObject<Aspose::Pdf::Facades::Bookmark>();
bm->set_Action(u"GoTo");
bm->set_PageNumber(1);
bm->set_Title(u"Parent");
// Set the Child Bookmarks
System::SharedPtr<Aspose::Pdf::Facades::Bookmarks> bms = System::MakeObject<Aspose::Pdf::Facades::Bookmarks>();
bms->Add(bm1);
bms->Add(bm2);
bm->set_ChildItem(bms);
// Add the Bookmarks to the PDF file
editor->CreateBookmarks(bm);
// Save the PDF document
editor->Save(u"OutputDirectory\\AddChildBookmark_out.pdf");
// Create an instance of the PdfBookmarkEditor class
System::SharedPtr<Aspose::Pdf::Facades::PdfBookmarkEditor> editor = System::MakeObject<Aspose::Pdf::Facades::PdfBookmarkEditor>();
// Load the PDF document
editor->BindPdf(u"SourceDirectory\\BookmarkSample.pdf");
// Delete all Bookmarks
editor->DeleteBookmarks();
// Save the PDF document
editor->Save(u"OutputDirectory\\DeleteAllBookmarks_out.pdf");
// Create an instance of the PdfBookmarkEditor class
System::SharedPtr<Aspose::Pdf::Facades::PdfBookmarkEditor> editor = System::MakeObject<Aspose::Pdf::Facades::PdfBookmarkEditor>();
// Load the PDF document
editor->BindPdf(u"SourceDirectory\\BookmarkSample.pdf");
// Delete a particular Bookmark
editor->DeleteBookmarks(u"bookmark for page 1");
// Save the PDF document
editor->Save(u"OutputDirectory\\DeleteParticularBookmark_out.pdf");
// Create an instance of the PdfBookmarkEditor class
System::SharedPtr<Aspose::Pdf::Facades::PdfBookmarkEditor> editor = System::MakeObject<Aspose::Pdf::Facades::PdfBookmarkEditor>();
// Load the PDF document
editor->BindPdf(u"SourceDirectory\\BookmarkSample.pdf");
// Modify Bookmark title
editor->ModifyBookmarks(u"bookmark for page 1", u"Page 1 Bookmark");
// Save the PDF document
editor->Save(u"OutputDirectory\\ModifyBookmark_out.pdf");
// Create an instance of the PdfBookmarkEditor class
System::SharedPtr<Aspose::Pdf::Facades::PdfBookmarkEditor> editor = System::MakeObject<Aspose::Pdf::Facades::PdfBookmarkEditor>();
// Load the PDF document
editor->BindPdf(u"SourceDirectory\\BookmarkSample.pdf");
// Retrieve all the Bookmarks
System::SharedPtr <Bookmarks> bms = editor->ExtractBookmarks();
// Loop through the Bookmarks
for (System::SharedPtr<Bookmark> bm : bms) {
// Display the title of the Bookmark
Console::WriteLine(bm->get_Title());
// Display the destination of the Bookmark
Console::WriteLine(bm->get_Destination());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment