Sha256: 88d1795533849ba87404ef93f2e841f36b82f3c1cfa1c3024eab8c777a1219f9

Contents?: true

Size: 874 Bytes

Versions: 37

Compression:

Stored size: 874 Bytes

Contents

# # Document Outline (Bookmarks)
#
# This example shows how to add a document outline, also known as
# bookmarks, to a PDF document.
#
# Usage:
# : `ruby outline.rb`
#

require 'hexapdf'

doc = HexaPDF::Document.new
6.times { doc.pages.add }

doc.outline.add_item("Main") do |main|
  main.add_item("Page 1", destination: 0)
  main.add_item("Page 2", destination: 1)
  main.add_item("Sub", flags: [:bold], text_color: "red", open: false) do |sub|
    sub.add_item("Page 3", destination: {type: :fit_page_horizontal, page: doc.pages[2], top: 480})
    sub.add_item("Page 4", destination: 3)
  end
  main.add_item("Page 5", destination: 4)
end
doc.outline.add_item("Appendix") do |appendix|
  dest = doc.destinations.use_or_create(5)
  appendix.add_item("Page 6", action: {S: :GoTo, D: dest})
end

doc.catalog[:PageMode] = :UseOutlines
doc.write('outline.pdf', optimize: true)

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
hexapdf-1.2.0 examples/022-outline.rb
hexapdf-1.1.1 examples/022-outline.rb
hexapdf-1.1.0 examples/022-outline.rb
hexapdf-1.0.3 examples/022-outline.rb
hexapdf-1.0.2 examples/022-outline.rb
hexapdf-1.0.1 examples/022-outline.rb
hexapdf-1.0.0 examples/022-outline.rb
hexapdf-0.47.0 examples/022-outline.rb
hexapdf-0.46.0 examples/022-outline.rb
hexapdf-0.45.0 examples/022-outline.rb
hexapdf-0.44.0 examples/022-outline.rb
hexapdf-0.41.0 examples/022-outline.rb
hexapdf-0.40.0 examples/022-outline.rb
hexapdf-0.39.1 examples/022-outline.rb
hexapdf-0.39.0 examples/022-outline.rb
hexapdf-0.38.0 examples/022-outline.rb
hexapdf-0.37.2 examples/022-outline.rb
hexapdf-0.37.1 examples/022-outline.rb
hexapdf-0.37.0 examples/022-outline.rb
hexapdf-0.36.0 examples/022-outline.rb