Bookmarks in a PDF file are helpful to mark points of interest in the document. These enable you to jump to a specific point in the document quickly. You might find yourself in situations where you need to add, read, modify or delete bookmarks in a PDF file programmatically. For that, this article will teach you how to work with bookmarks in PDF files using C++.

C++ API for Working with Bookmarks in PDF Files

Aspose.PDF for C++ is a C++ library that allows you to create, read and update PDF documents. Furthermore, the API supports adding, reading, modifying, and removing bookmarks from PDF files. You can either install the API through NuGet or download it directly from the downloads section.

PM> Install-Package Aspose.PDF.Cpp

Add Bookmarks in PDF Files using C++

The following are the steps to add a bookmark in a PDF file.

The following sample code demonstrates how to add a bookmark in a PDF file using C++.

Output generated by the sample code

Output generated by the sample code

Add Nested Bookmarks in PDF Files

You can also add nested bookmarks using the Aspose.PDF for C++ API. The following are the steps for adding nested bookmarks.

The following sample code shows how to add nested bookmarks in a PDF file using C++.

Output generated by the sample code

Output generated by the sample code

Read Bookmarks from a PDF File using C++

In order to read the bookmarks, use the PdfBookmarkEditor->ExtractBookmarks() method. The following are the steps to read bookmarks from a PDF file.

The following sample code shows how to read bookmarks from a PDF file using C++.

Modify Bookmark Title using C++

The following are the steps to modify the title of an existing bookmark in a PDF file.

The following sample code demonstrates how to modify the title of an existing bookmark in a PDF file.

Delete a Particular Bookmark using C++

The API provides the PdfBookmarkEditor->DeleteBookmarks(System::String title) method to delete a particular bookmark from a PDF file. The following are the steps to delete a specific bookmark.

The following sample code shows how to delete a particular bookmark using C++.

Delete all Bookmarks in a PDF File using C++

Instead of deleting bookmarks one at a time, you can remove all the bookmarks at once using the PdfBookmarkEditor->DeleteBookmarks() method. The following are the steps to delete all bookmarks in a PDF file.

The following is the sample code to delete all bookmarks in a PDF file.

Get a Free License

You can try the API without evaluation limitations by requesting a free temporary license.

Conclusion

In this article, you have learned how to work with bookmarks in PDF files using C++. Specifically, you have learned how to add, read, modify and delete bookmarks in a PDF file. Furthermore, you have seen how to add nested bookmarks using the Aspose.PDF for C++ API. The API provides many additional features for working with PDF files that you can explore in detail by using the official documentation. If you have any questions, please feel free to contact us on the free support forum.

See Also