Set bookmark title : Bookmarks « PDF « Java Tutorial






import java.io.FileOutputStream;

import com.lowagie.text.ChapterAutoNumber;
import com.lowagie.text.Document;
import com.lowagie.text.Phrase;
import com.lowagie.text.Section;
import com.lowagie.text.pdf.PdfWriter;

public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
    document.open();
    Phrase text = new Phrase("test. ");
    ChapterAutoNumber chapter1 = new ChapterAutoNumber("This is a sample sentence:");
    chapter1.setBookmarkTitle("The fox");
    chapter1.setBookmarkOpen(false);
    Section section1 = chapter1.addSection("Quick");
    section1.add(text);
    document.add(chapter1);
    ChapterAutoNumber chapter2 = new ChapterAutoNumber("Jumps");
    Section section = chapter2.addSection("Over");
    section.add(text);
    document.add(chapter2);
    document.close();
  }
}








29.33.Bookmarks
29.33.1.Add bookmark
29.33.2.Read PDF File to retrieve the bookmarks
29.33.3.Set bookmark title
29.33.4.Pdf SimpleBookmark
29.33.5.Copy book mark