Skip to content

Instantly share code, notes, and snippets.

@aspose-com-kb
Last active February 4, 2022 13:20
How to Read Bookmark from PDF in C++. More details on this topic are available here: https://kb.aspose.com/pdf/cpp/how-to-read-bookmarks-in-pdf-file-using-c++/
#pragma once
#include <iostream>
#include <system/smart_ptr.h>
#include <Aspose.PDF.Cpp/License.h>
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/Facades/PdfBookmarkEditor.h>
#include <Aspose.PDF.Cpp/Facades/Bookmark.h>
#include <Aspose.PDF.Cpp/Facades/Bookmarks.h>
#include <system/console.h>
#include <system/io/file.h>
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Facades;
class ReadBookmarkEx{
public:
void ReadPDFBookmark()
{
// Set the license for Aspose.PDF for C++ to Read the bookmarks in PDF file
SharedPtr<License> ReadPdfBookmarkLicense = System::MakeObject<License>();
ReadPdfBookmarkLicense->SetLicense(u"Aspose.Pdf.lic");
// Initialize an object of PdfBookmarkEditor class to get bookmarks
SharedPtr<PdfBookmarkEditor> BookmarkEditor = System::MakeObject<PdfBookmarkEditor>();
// Load the input PDF document for extracting bookmarks
BookmarkEditor->BindPdf(u"BookmarkSample.pdf");
// Retrieve the Bookmarks from the PDF
SharedPtr <Bookmarks> bookmarks = BookmarkEditor->ExtractBookmarks();
// Iterate through all the Bookmarks
for (SharedPtr<Bookmark> bookmark : bookmarks)
{
// Read different properties of the bookmark
Console::WriteLine(bookmark->get_Title());
Console::WriteLine(bookmark->get_ItalicFlag());
Console::WriteLine(bookmark->get_BoldFlag());
Console::WriteLine(bookmark->get_TitleColor().ToString());
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment