All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ironsoftware.ironpdf.bookmark.BookmarkManager Maven / Gradle / Ivy

Go to download

IronPDF Java library offers an extensive compatibility range, making it a go-to solution for a wide array of developers. It fully supports JVM languages like Java, Scala, and Kotlin, making it incredibly versatile. This Java PDF library is also compatible with Java 8 and above, providing optimum performance across multiple platforms. It's been designed with a wide range of users in mind Here's a look at what it supports: JVM Languages: Java, Scala, Kotlin.Platforms: Java 8 and above.Operating Systems: Microsoft Windows, Linux, Docker, Azure, AWS.IDEs: Jetbrains IntelliJ IDEA, Eclipse. You can deploy IronPDF Java across various platforms, including Microsoft Windows, Linux, Docker, Azure, and AWS. It is also fully compatible with popular IDEs like Jetbrains IntelliJ IDEA and Eclipse, facilitating smooth project development and management. Your pom.xml file is essentially the backbone of your project when you're using Maven. It's here where you introduce new dependencies that you wish to include. To make IronPDF Java package a part of your Maven project, you simply need to add the following snippets to your pom.xml: Remember to replace '20xx.xx.xxxx' with the latest version of IronPDF. IronPDF Java simplifies the process of creating PDF files. Convert HTML files, HTML strings, or URLs directly to new PDF documents in a few lines of code. The variety of file formats it handles is vast, as it can even transform images into PDF documents and vice versa. Need to use base 64 encoding, base URLs, or custom file paths? No problem! IronPDF Java has got you coveredFor more detail about installing and using IronPDF Java. When you run your project for the first time post-integration, IronPDF's engine binaries will automatically be downloaded. The engine starts its journey when you call any IronPDF function for the first time and takes a breather when your application is either closed or enters an idle state. It is not an open source java PDF library but here's the best part - IronPDF Java is offering a 30-day free trial. So, why wait? Give it a go and boost your PDF operations today.

There is a newer version: 2024.10.1
Show newest version
package com.ironsoftware.ironpdf.bookmark;

import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.internal.staticapi.BookmarkDescriptor;
import com.ironsoftware.ironpdf.internal.staticapi.Bookmark_Api;
import com.ironsoftware.ironpdf.internal.staticapi.InternalPdfDocument;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;


/**
 * Class used to add , edit and remove bookmarks from a {@link com.ironsoftware.ironpdf.PdfDocument} outline.
 * 

Bookmarks are arranged and navigated in a parent/child node hierarchy, similar to an HTML DOM.

*

See: {@link com.ironsoftware.ironpdf.PdfDocument#getBookmark()}

*

See: {@link Bookmark}

*/ public class BookmarkManager { private final InternalPdfDocument internalPdfDocument; /** * Please get BookmarkManager by {@link PdfDocument#getBookmark()} instead. * * @param internalPdfDocument the internal pdf document */ public BookmarkManager(InternalPdfDocument internalPdfDocument) { this.internalPdfDocument = internalPdfDocument; } /** * Total number of bookmarks, including all nested bookmarks * * @return Bookmarks count */ public final int getCount() { return this.getBookmarks().size(); } /** * Retrieve all bookmarks within this PDF, recursively retrieve all children of bookmarks within * this collection, and return as a flat list * * @return A flattened list of all bookmark ojects in this collection and all of their children */ public final List getBookmarks() { return Bookmark_Api.getBookmarks(internalPdfDocument) .stream().peek(x -> x.setBookmarkManager(this)).collect(Collectors.toList()); } /** * Add a new bookmark at the end of the bookmark collection * * @param text The display text for the link. * @param pageIndex The zero based page number to link to. E.g. Page 1 has a PageIndex of 0 */ public final void addBookMarkAtEnd(String text, int pageIndex) { List bookmarks = this.getBookmarks(); com.ironsoftware.ironpdf.bookmark.Bookmark lastBookmarks = bookmarks.size() == 0 ? null : bookmarks.get(bookmarks.size() - 1); if (lastBookmarks == null) { Bookmark_Api.insertBookmarkAtStart(internalPdfDocument, pageIndex, text); } else { Bookmark_Api.insertBookmark(internalPdfDocument, pageIndex, text, lastBookmarks.getParentBookmarkText(), lastBookmarks.getText()); } } /** * Add a new bookmark at the start of the document collection * * @param text The display text for the link. * @param pageIndex The zero based page number to link to. E.g. Page 1 has a PageIndex of 0 */ public final void addBookMarkAtStart(String text, int pageIndex) { Bookmark_Api.insertBookmarkAtStart(internalPdfDocument, pageIndex, text); } /** * Insert a new bookmark * * @param text The display text for the link. * @param pageIndex The zero based page number to link to. E.g. Page 1 has a * PageIndex of 0 * @param parentText parent bookmark text. set to null for insert at the top * @param previousText previous bookmark text. set to null for insert at first of its * siblings */ public final void insertBookmark(String text, int pageIndex, String parentText, String previousText) { Bookmark_Api.insertBookmark(internalPdfDocument, pageIndex, text, parentText, previousText); } /** * Insert a new bookmark * * @param bookmark a bookmark object. */ public final void insertBookmark(Bookmark bookmark) { Bookmark_Api.insertBookmark(internalPdfDocument, bookmark.getPageIndex(), bookmark.getText(), bookmark.getParentBookmarkText(), bookmark.getPreviousBookmarkText()); } /** * Add a new bookmark as a first child of this bookmark. To add a bookmark as a second child, * please navigate to the childBookmark object and call AddNextBookmark. * * @param text The display text for the link. * @param pageIndex The zero based page number to link to. E.g. Page 1 has a PageIndex of 0 * @param parentBookmarkText bookmark parent text, set empty if bookmark does not have parent. * @return a new child bookmark */ public final com.ironsoftware.ironpdf.bookmark.Bookmark addChildBookmark(String text, int pageIndex, String parentBookmarkText) { Bookmark_Api.insertBookmark(internalPdfDocument, pageIndex, text, parentBookmarkText, null); //hacks to get the new bookmark, as the static api doesn't return it. Optional optNewBookmark = Bookmark_Api.getBookmarks( internalPdfDocument).stream().filter(x -> x.getText().equals(text) && x.getPageIndex() == pageIndex && x.getParentBookmarkText().equals(parentBookmarkText)) .findFirst(); optNewBookmark.ifPresent(x -> x.setBookmarkManager(this)); return optNewBookmark.orElse(null); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy