📄 pdfbookmark.java
字号:
// $Id: PDFBookmark.java,v 1.5 2003/11/04 17:16:01 mike Exp $package org.faceless.pdf;import java.util.*;import java.awt.Color;/** * <p> * This class describes the <code>Bookmark</code> or <code>Outline</code> * part of a PDF document - the "Table of Contents" structure that allows * easy navigation through the document. * </p> * <p> * Bookmarks are structured like a directory tree, with each node on the * tree having zero or more children. The top of the tree is always the * document itself. * </p> * <b>Example</b> * <p> * Here's an example of a simple bookmark tree, and the code that creates it. * </p> * <pre> * +-- Section 1 -+-- SubSection 1.1 * | | * | +-- SubSection 1.2 * | * +-- Section 2 * </pre> * * <pre> * PDF pdf = new PDF(); * * // Add the top level bookmarks "Section 1" and "Section 2" to the document. * List topbookmarks = pdf.getBookmarks(); * PDFBookmark s1 = new PDFBookmark("Section 1", someaction); * PDFBookmark s2 = new PDFBookmark("Section 2", someaction); * topbookmarks.add(s1); * topbookmarks.add(s2); * * // Add the bookmarks under "Section 1" * List s1bookmarks = s1.getBookmarks(); * PDFBookmark s11 = new PDFBookmark("SubSection 1.1", someaction); * PDFBookmark s12 = new PDFBookmark("SubSection 1.2", someaction); * s1bookmarks.add(s11); * s1bookmarks.add(s12); * </pre> * <p> * There is no limit to the number of bookmarks in a PDF document or to the * level they are nested. * </p> * @version $Revision: 1.5 $ */public class PDFBookmark extends PeeredObject{ private final org.faceless.pdf2.PDFBookmark bookmark; Object getPeer() { return bookmark; } PDFBookmark(org.faceless.pdf2.PDFBookmark bookmark) { this.bookmark=bookmark; } /** * Create a new bookmark with an initial state of "closed". * @param name The name of the bookmark as seen by the user. May include * non-ASCII Unicode characters. * @param action the action to perform when the bookmark is selected */ public PDFBookmark(String name, PDFAction action) { this(name,action,false); } /** * Create a new bookmark and set the initial state to "open" or "closed" * @param name The name of the bookmark as seen by the user. May include * non-ASCII Unicode characters. * @param action The action to perform when the bookmark is selected * @param open Whether the bookmark is open by default * @since 1.0.4 */ public PDFBookmark(String name, PDFAction action, boolean open) { bookmark = new org.faceless.pdf2.PDFBookmark(name, action==null ? null : action.action, open); } /** * Return the a List containing this bookmarks children. The list * has zero or more elements * of type <code>PDFBookmark</code>. * @return the list of bookmarks */ public List getBookmarks() { return new ListPeer(bookmark.getBookmarks()); } /** * Set the color of the Bookmark. * This feature is only available in Acrobat 5 or later (PDF 1.4), * but <i>should</i> be safely ignored by earlier viewers. * @since 1.1 */ public void setColor(Color c) { bookmark.setColor(c); } /** * Set the style of the Bookmark to <i>italic</i>, <b>bold</b> or * <b><i>both</i></b>. * This feature is only available in Acrobat 5 or later (PDF 1.4), * but <i>should</i> be safely ignored by earlier viewers. * @since 1.1 */ public void setStyle(boolean italic, boolean bold) { bookmark.setStyle(italic, bold); } /** * Set the action this bookmark performs when selected * @param action the action to perform when the bookmark is activated - may be <tt>null</tt> * @since 1.1.12 */ public void setAction(PDFAction action) { bookmark.setAction(action==null ? null : action.action); } /** * Get the action this bookmark performs when selected * @return the action performed when the bookmark is activated - may be <tt>null</tt> * @since 1.1.12 */ public PDFAction getAction() { return (PDFAction)PeeredObject.getPeer(bookmark.getAction()); } /** * Set the name of this bookmark * @param name The name of the bookmark as seen by the user. May include * non-ASCII Unicode characters. * @since 1.1.12 */ public void setName(String name) { bookmark.setName(name); } /** * Get the name of this bookmark * @return the name of the bookmark as seen by the user * @since 1.1.12 */ public String getName() { return bookmark.getName(); } public String toString() { String s = "<bookmark name=\""+getName()+"\""; if (getAction()!=null) { s+=" action=\""+getAction()+"\""; } return s+"/>"; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -