class HexaPDF:: Type:: Outline
Parent | HexaPDF::Dictionary |
---|
Represents the root of the PDF’s document outline containing a hierarchy of outline items (sometimes called bookmarks) in a linked list.
The document outline usually contains items for the sections of the document, so that clicking on an item opens the page where the section starts (the section header is). Most PDF viewers are able to display the outline to aid in navigation, though not all apply the optional attributes like the text color.
The outline dictionary is linked via the /Outlines entry from the Type::Catalog
and can directly be accessed via HexaPDF::Document#outline
.
Examples¶ ↑
Here is an example for creating an outline:
doc = HexaPDF::Document.new
5.times { doc.pages.add }
doc.outline.add_item("Section 1", destination: 0) do |sec1|
sec1.add_item("Page 2", destination: doc.pages[1])
sec1.add_item("Page 3", destination: 2)
sec1.add_item("Section 1.1", text_color: "red", flags: [:bold]) do |sec11|
sec11.add_item("Page 4", destination: 3)
end
end
Here is one for copying the complete outline from one PDF to another:
doc = HexaPDF::Document.open(ARGV[0])
target = HexaPDF::Document.new
stack = [target.outline]
doc.outline.each_item do |item, level|
if stack.size < level
stack << stack.last[:Last]
elsif stack.size > level
(stack.size - level).times { stack.pop }
end
stack.last.add_item(target.import(item))
end
# Copying all the pages so that the references work.
doc.pages.each {|page| target.pages << target.import(page) }
See: PDF2.0 s12.3.3
Field Definitions
Name | Type/Allowed Values | Required | Default Value |
---|---|---|---|
Type | Symbol | false | :Outlines |
First | HexaPDF::Type::OutlineItem or Hash | false | nil |
Last | HexaPDF::Type::OutlineItem or Hash | false | nil |
Count | Integer | false | nil |
Public Instance Methods
Adds a new top-level outline item.
See OutlineItem#add_item
for details on the available options since this method just passes all arguments through to it.