HelloWorldBookmarks.java Source code

Java tutorial

Introduction

Here is the source code for HelloWorldBookmarks.java

Source

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.SimpleBookmark;

public class HelloWorldBookmarks {
    public static void main(String[] args) throws Exception {
        PdfReader reader = new PdfReader("HelloWorldRead.pdf");
        List list = SimpleBookmark.getBookmark(reader);
        for (Iterator i = list.iterator(); i.hasNext();) {
            showBookmark((Map) i.next());
        }
    }

    private static void showBookmark(Map bookmark) {
        System.out.println(bookmark.get("Title"));
        ArrayList kids = (ArrayList) bookmark.get("Kids");
        if (kids == null)
            return;
        for (Iterator i = kids.iterator(); i.hasNext();) {
            showBookmark((Map) i.next());
        }
    }

}