How to Add PDF Bookmarks and Outline in Java

IronPDF's Java library enables you to programmatically add bookmarks and outlines to PDF documents using the BookmarkManager class, supporting both single-layer and multi-layer bookmark structures with customizable navigation points.

Quickstart: Add PDF Bookmarks in Java

  1. Install IronPDF Java library and set your license key
  2. Load your PDF using PdfDocument.fromFile()
  3. Get the BookmarkManager with pdf.getBookmark()
  4. Add bookmarks using addBookMarkAtEnd("Title", pageNumber)
  5. Save the PDF with pdf.saveAs()

```java :title=Quickstart PdfDocument pdf = PdfDocument.fromFile(Path.of("document.pdf")); BookmarkManager bookmarks = pdf.getBookmark(); bookmarks.addBookMarkAtEnd("Chapter 1", 0); pdf.saveAs(Path.of("bookmarked.pdf"));


PDF bookmarks significantly improve the usability and navigation of your documents. Outlines provide structured navigation within PDFs, allowing users to jump directly to key sections like a table of contents. This functionality proves essential when working with lengthy documents, reports, or multi-chapter PDFs that require organized navigation.

IronPDF simplifies PDF manipulation in Java applications. Its bookmarking functionality provides straightforward methods for creating custom bookmarks in PDF files. The library integrates seamlessly with Java applications and supports various PDF manipulation features beyond bookmarking, including [merging PDFs](https://ironpdf.com/java/how-to/java-merge-pdf-tutorial/), [creating forms](https://ironpdf.com/java/how-to/create-forms/), and [adding watermarks](https://ironpdf.com/java/how-to/custom-watermark/).

<div class="hsg-featured-snippet">
    <h2>How to Add PDF Bookmarks and Outline</h2>
    <ol>
        <li><a href="https://ironpdf.com/java/#download-modal">Install Java library to add bookmarks to PDFs</a></li>
        <li>Utilize the <strong>`PdfDocument`</strong> class to load an existing PDF file in Java</li>
        <li>Create and customize the bookmarks with the <strong>`BookmarkManager`</strong> class</li>
        <li>Use `addBookMarkAtEnd` to add bookmarks to specific pages of the PDF</li>
        <li>Save the PDF document containing the new outline and bookmarks</li>
    </ol>
</div>

## What Do I Need Before Getting Started?

Before implementing PDF bookmarks, ensure you have IronPDF properly configured in your Java project. The library requires Java 8 or higher and can be easily integrated using Maven or Gradle. You'll need to add the IronPDF dependency to your project's build file. For detailed setup instructions, refer to the [Get Started Overview](https://ironpdf.com/java/docs/).

You must also ensure your license key is configured correctly, as IronPDF requires licensing for development. For comprehensive information about licensing options and implementation, visit the [licensing guide](https://ironpdf.com/java/get-started/license-keys/). Set the license key at the beginning of your application before using any IronPDF functionality.

## How Do I Add Outline & Bookmarks to a PDF?

For this example, I will use this [sample PDF](/static-assets/ironpdf-java/howto/bookmarks/NovelSample.pdf) to apply the outline and bookmarks. The process involves loading an existing PDF document and utilizing IronPDF's `BookmarkManager` to add navigation points throughout the document.

### How Can I Add a Single Layer of Bookmarks?

After loading this PDF from the specified file path using the [`PdfDocument`.fromFile](https://ironpdf.com/java/object-reference/api/com/ironsoftware/ironpdf/PdfDocument.html) class, retrieve the [`BookmarkManager`](https://ironpdf.com/java/object-reference/api/com/ironsoftware/ironpdf/bookmark/BookmarkManager.html) object to start adding bookmarks. You can add bookmarks to the start or end of the bookmark collection using the `addBookMarkAtEnd` and `addBookMarkAtStart` methods. These methods provide flexibility in organizing your bookmarks according to your document's structure.

TipsRemember that all page indexes follow zero-based indexing.
```java import java.io.IOException; import java.nio.file.Path; import com.ironsoftware.ironpdf.License; import com.ironsoftware.ironpdf.PdfDocument; import com.ironsoftware.ironpdf.bookmark.BookmarkManager; public class Main { public static void main(String[] args) throws IOException { // Set the license key for IronPDF License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01"); // Load the PDF file PdfDocument pdf = PdfDocument.fromFile(Path.of("NovelSample.pdf")); // Get BookmarkManager object to manage bookmarks BookmarkManager bookmarks = pdf.getBookmark(); // Add bookmarks at the end of the bookmark collection bookmarks.addBookMarkAtEnd("Title Page", 0); bookmarks.addBookMarkAtEnd("Table of Contents", 1); bookmarks.addBookMarkAtEnd("Dedication Page", 2); bookmarks.addBookMarkAtEnd("First Page", 3); bookmarks.addBookMarkAtStart("Page 4", 6); // Save the modified PDF with bookmarks pdf.saveAs(Path.of("bookmarked.pdf")); } }

With the PDF viewer above, check the table of contents located at the top left corner of most browsers to see all added bookmarks. This single-layer bookmark structure provides straightforward navigation for documents with simple organizational needs.

How Do I Create Multiple Layers of Bookmarks?

In this example, start by adding bookmarks just like creating a single layer of bookmarks. Next, use the insertBookmark method to add a new bookmark on a new layer. The first parameter specifies the bookmark name, and the second parameter specifies the page the bookmark links to. To create a new layer, make the new bookmark a "child" of an existing bookmark using the method's third parameter. This hierarchical structure suits documents with chapters, sections, and subsections.

import java.io.IOException;
import java.nio.file.Path;
import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.bookmark.BookmarkManager;

public class Main {
    public static void main(String[] args) throws IOException {
        // Set the license key
        License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");

        // Load the PDF file
        PdfDocument pdf = PdfDocument.fromFile(Path.of("NovelSample.pdf"));

        // Get BookmarkManager object
        BookmarkManager bookmarks = pdf.getBookmark();

        // Add bookmarks at the end
        bookmarks.addBookMarkAtEnd("Title Page", 0);
        bookmarks.addBookMarkAtEnd("Table of Contents", 1);
        bookmarks.addBookMarkAtEnd("Dedication", 2);

        // Insert second layer bookmarks
        bookmarks.insertBookmark("First Page", 3, "Table of Contents", null);
        bookmarks.insertBookmark("Second Page", 4, "Table of Contents", "First Page");
        bookmarks.insertBookmark("End of Sample", 7, "Title Page", null);
        bookmarks.insertBookmark("Fourth page", 6, "Table of Contents", "Second Page");

        // Save the modified PDF with multiple layer bookmarks
        pdf.saveAs(Path.of("multiLayer.pdf"));
    }
}
import java.io.IOException;
import java.nio.file.Path;
import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.bookmark.BookmarkManager;

public class Main {
    public static void main(String[] args) throws IOException {
        // Set the license key
        License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");

        // Load the PDF file
        PdfDocument pdf = PdfDocument.fromFile(Path.of("NovelSample.pdf"));

        // Get BookmarkManager object
        BookmarkManager bookmarks = pdf.getBookmark();

        // Add bookmarks at the end
        bookmarks.addBookMarkAtEnd("Title Page", 0);
        bookmarks.addBookMarkAtEnd("Table of Contents", 1);
        bookmarks.addBookMarkAtEnd("Dedication", 2);

        // Insert second layer bookmarks
        bookmarks.insertBookmark("First Page", 3, "Table of Contents", null);
        bookmarks.insertBookmark("Second Page", 4, "Table of Contents", "First Page");
        bookmarks.insertBookmark("End of Sample", 7, "Title Page", null);
        bookmarks.insertBookmark("Fourth page", 6, "Table of Contents", "Second Page");

        // Save the modified PDF with multiple layer bookmarks
        pdf.saveAs(Path.of("multiLayer.pdf"));
    }
}
JAVA

Here you can see the PDF with our new tree structure of bookmarks. Check the outline to see how the insertBookmark feature added a new layer of bookmarks. This multi-layer approach suits technical documentation, academic papers, or any document requiring detailed navigation structure.


How Do I Retrieve Existing Bookmarks from a PDF?

IronPDF's bookmarking tool not only adds new bookmarks but also retrieves and views existing ones. This functionality proves essential when modifying existing PDFs or analyzing their structure. To navigate through bookmarks, first load the PDF using the PdfDocument.fromFile method. Then access the BookmarkManager object and use the getBookmarks method to retrieve all bookmarks, including child bookmarks. Finally, use the get method to retrieve a bookmark by its index in the list. This capability allows programmatic inspection and manipulation of existing PDF navigation structures.

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.bookmark.Bookmark;
import com.ironsoftware.ironpdf.bookmark.BookmarkManager;

public class Main {
    public static void main(String[] args) throws IOException {
        // Set the license key
        License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");

        // Load the PDF file with bookmarks
        PdfDocument pdf = PdfDocument.fromFile(Path.of("bookmarked.pdf"));

        // Retrieve the bookmark manager
        BookmarkManager bookmarks = pdf.getBookmark();

        // Retrieve list of all bookmarks
        List<Bookmark> bookmarkList = bookmarks.getBookmarks();

        // Retrieve a specific bookmark by its index
        Bookmark bookmark = bookmarkList.get(2);

        // Print bookmark details
        System.out.println("Bookmark Title: " + bookmark.getText());
        System.out.println("Page Number: " + bookmark.getPageIndex());

        // Check if bookmark has children
        if(bookmark.getChildren() != null && !bookmark.getChildren().isEmpty()) {
            System.out.println("Number of child bookmarks: " + bookmark.getChildren().size());
        }
    }
}
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.bookmark.Bookmark;
import com.ironsoftware.ironpdf.bookmark.BookmarkManager;

public class Main {
    public static void main(String[] args) throws IOException {
        // Set the license key
        License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");

        // Load the PDF file with bookmarks
        PdfDocument pdf = PdfDocument.fromFile(Path.of("bookmarked.pdf"));

        // Retrieve the bookmark manager
        BookmarkManager bookmarks = pdf.getBookmark();

        // Retrieve list of all bookmarks
        List<Bookmark> bookmarkList = bookmarks.getBookmarks();

        // Retrieve a specific bookmark by its index
        Bookmark bookmark = bookmarkList.get(2);

        // Print bookmark details
        System.out.println("Bookmark Title: " + bookmark.getText());
        System.out.println("Page Number: " + bookmark.getPageIndex());

        // Check if bookmark has children
        if(bookmark.getChildren() != null && !bookmark.getChildren().isEmpty()) {
            System.out.println("Number of child bookmarks: " + bookmark.getChildren().size());
        }
    }
}
JAVA

How Can I Insert a Bookmark at a Specific Index?

With retrieved bookmarks, you can add new bookmarks at specific indexes within the document. This feature helps when updating existing PDFs with new sections or reorganizing document structure. To accomplish this, select the targeted bookmark and use the addNextBookmark method to add a new bookmark after it. For example, take the PDF from the 'Add Multiple Layers of Bookmarks' section and add a bookmark after the 'Third Page' bookmark. You can also add a child bookmark as a deeper layer using the addChildBookmark method, allowing precise control over your document's navigation hierarchy.

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.bookmark.Bookmark;
import com.ironsoftware.ironpdf.bookmark.BookmarkManager;

public class Main {
    public static void main(String[] args) throws IOException {
        // Set the license key
        License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");

        // Load the PDF we modified earlier
        PdfDocument pdf = PdfDocument.fromFile(Path.of("multiLayer.pdf"));

        // Get the BookmarkManager
        BookmarkManager bookmarks = pdf.getBookmark();

        // Retrieve the list of bookmarks
        List<Bookmark> bookmarkList = bookmarks.getBookmarks();

        // Retrieve a specific bookmark by its index
        Bookmark bookmark = bookmarkList.get(5);

        // Add a new bookmark after the specified bookmark
        bookmark.addNextBookmark("Fourth Page", 6);

        // Add another layer to 'Third page' bookmark
        bookmark.addChildBookmark("Section 1", 7);

        // Save the modified PDF
        pdf.saveAs(Path.of("specificIndex.pdf"));
    }
}
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.bookmark.Bookmark;
import com.ironsoftware.ironpdf.bookmark.BookmarkManager;

public class Main {
    public static void main(String[] args) throws IOException {
        // Set the license key
        License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");

        // Load the PDF we modified earlier
        PdfDocument pdf = PdfDocument.fromFile(Path.of("multiLayer.pdf"));

        // Get the BookmarkManager
        BookmarkManager bookmarks = pdf.getBookmark();

        // Retrieve the list of bookmarks
        List<Bookmark> bookmarkList = bookmarks.getBookmarks();

        // Retrieve a specific bookmark by its index
        Bookmark bookmark = bookmarkList.get(5);

        // Add a new bookmark after the specified bookmark
        bookmark.addNextBookmark("Fourth Page", 6);

        // Add another layer to 'Third page' bookmark
        bookmark.addChildBookmark("Section 1", 7);

        // Save the modified PDF
        pdf.saveAs(Path.of("specificIndex.pdf"));
    }
}
JAVA

Please noteIf you merge two PDF documents together whose bookmarks share identical names, this can disrupt the bookmark list itself.

When working with bookmarks in complex PDF workflows, consider exploring IronPDF's other features such as splitting PDFs to create smaller documents with their own bookmark structures, or printing PDFs with bookmark navigation intact. For more advanced examples and complete code demonstrations, check the bookmarks code example in our examples section.

Frequently Asked Questions

How do I add bookmarks to a PDF document in Java?

You can add bookmarks to PDF documents using IronPDF's BookmarkManager class. First, load your PDF using PdfDocument.fromFile(), then access the BookmarkManager with pdf.getBookmark(), and add bookmarks using the addBookMarkAtEnd() method specifying the bookmark title and page number.

What are the prerequisites for adding PDF bookmarks programmatically?

To add PDF bookmarks with IronPDF, you need Java 8 or higher, the IronPDF library integrated via Maven or Gradle, and a valid license key configured in your application. The library supports both single-layer and multi-layer bookmark structures.

Can I create multi-level bookmark hierarchies in PDFs?

Yes, IronPDF supports creating both single-layer and multi-layer bookmark structures. You can create hierarchical navigation with parent and child bookmarks using the BookmarkManager class for organizing complex PDF documents.

What is the purpose of PDF bookmarks and outlines?

PDF bookmarks and outlines significantly improve document usability by providing structured navigation. They allow users to jump directly to key sections like a table of contents, which is especially valuable for lengthy documents, reports, or multi-chapter PDFs. IronPDF makes it easy to implement these navigation features programmatically.

What other PDF manipulation features are available besides bookmarking?

Beyond adding bookmarks, IronPDF offers comprehensive PDF manipulation capabilities including merging PDFs, creating forms, adding watermarks, and various other document processing features. These functionalities integrate seamlessly with Java applications for complete PDF management.

How do I save a PDF after adding bookmarks?

After adding bookmarks using IronPDF's BookmarkManager, save the modified PDF document by calling the saveAs() method on your PdfDocument object, specifying the output file path where you want to save the bookmarked PDF.

Darrius Serrant
Full Stack Software Engineer (WebOps)

Darrius Serrant holds a Bachelor’s degree in Computer Science from the University of Miami and works as a Full Stack WebOps Marketing Engineer at Iron Software. Drawn to coding from a young age, he saw computing as both mysterious and accessible, making it the perfect medium for creativity ...

Read More
Ready to Get Started?
Version: 2026.1 just released