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

com.ironsoftware.ironpdf.internal.staticapi.Bookmark_Converter 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.internal.staticapi;

import com.ironsoftware.ironpdf.bookmark.Bookmark;
import com.ironsoftware.ironpdf.bookmark.BookmarkDestinations;
import com.ironsoftware.ironpdf.internal.proto.PdfBookmarkCollectionP;
import com.ironsoftware.ironpdf.internal.proto.PdfiumBookmarkDescriptorCollectionP;

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

import static com.ironsoftware.ironpdf.bookmark.BookmarkDestinations.PAGE;

final class Bookmark_Converter {

    static List fromProto(PdfiumBookmarkDescriptorCollectionP proto) {
        return convertDescriptorsToBookmarks(proto.getBookmarkDescriptorsList().stream().map(Bookmark_Converter::fromProto)
                .collect(Collectors.toList()));
    }

    static BookmarkDescriptor fromProto(com.ironsoftware.ironpdf.internal.proto.PdfiumBookmarkDescriptorP proto) {
        return new BookmarkDescriptor(proto.getHierarchy(),
                proto.getPageIndex(),
                proto.getText());
    }

    public static List convertDescriptorsToBookmarks(List descriptors) {
        List bookmarks = new ArrayList<>();

        final String regex = "\\\\";
        for (int i = 0; i < descriptors.size(); i++) {
            BookmarkDescriptor descriptor = descriptors.get(i);

            String text = descriptor.getText();
            int pageIndex = descriptor.getPageIndex();

            // Setting parentBookmarkText using the hierarchy
            String[] hierarchyParts = Arrays.stream(descriptor.getHierarchy().split(regex)).filter(part -> !part.isEmpty()).toArray(String[]::new);
            String parentBookmarkText = "";
            if (hierarchyParts.length > 1) { // Check to ensure there's a parent
                parentBookmarkText = hierarchyParts[hierarchyParts.length - 1]; // Parent is the second last element in split
            }

            // Setting previous and next bookmark text
            String previousBookmarkText = "";
            String nextBookmarkText = "";

            if (i > 0) {
                BookmarkDescriptor prevDescriptor = descriptors.get(i - 1);
                String[] prevHierarchyParts = Arrays.stream(prevDescriptor.getHierarchy().split(regex)).filter(part -> !part.isEmpty()).toArray(String[]::new);
                String prevParent = (prevHierarchyParts.length > 1) ? prevHierarchyParts[prevHierarchyParts.length - 1] : "";

                if (parentBookmarkText != null && parentBookmarkText.equals(prevParent)) {
                    previousBookmarkText = prevDescriptor.getText();
                }
            }

            if (i < descriptors.size() - 1) {
                BookmarkDescriptor nextDescriptor = descriptors.get(i + 1);
                String[] nextHierarchyParts = Arrays.stream(nextDescriptor.getHierarchy().split(regex)).filter(part -> !part.isEmpty()).toArray(String[]::new);
                String nextParent = (nextHierarchyParts.length > 1) ? nextHierarchyParts[nextHierarchyParts.length - 1] : "";

                if (parentBookmarkText != null && parentBookmarkText.equals(nextParent)) {
                    nextBookmarkText = nextDescriptor.getText();
                }
            }

            bookmarks.add(new Bookmark(text, pageIndex, parentBookmarkText, PAGE, nextBookmarkText, previousBookmarkText));
        }

        return bookmarks;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy