Module: PDF_Bookmark
- Defined in:
- lib/pdf_paradise/fpdf/bookmark.rb
Overview
#
Translation of the bookmark class from the PHP FPDF script from Olivier Plathey.
Translated by Sylvain Lafleur and ?? with the help of Brian Ollenberger
First added in 1.53b
Usage is as follows:
require 'fpdf'
require 'bookmark'
pdf = FPDF.new
pdf.extend(PDF_Bookmark)
This allows it to be combined with other extensions, such as the Chinese module.
#
Class Method Summary collapse
-
.extend_object(i) ⇒ Object
# === PDF_Bookmark.extend_object ========================================================================= #.
Instance Method Summary collapse
-
#bookmark(txt, level = 0, y = 0) ⇒ Object
(also: #Bookmark)
# === bookmark ========================================================================= #.
-
#putbookmarks ⇒ Object
# === putbookmarks ========================================================================= #.
-
#putcatalog ⇒ Object
# === putcatalog ========================================================================= #.
-
#putresources ⇒ Object
# === putresources ========================================================================= #.
Class Method Details
.extend_object(i) ⇒ Object
#
PDF_Bookmark.extend_object
#
27 28 29 30 |
# File 'lib/pdf_paradise/fpdf/bookmark.rb', line 27 def self.extend_object(i) i.instance_eval('@outlines,@OutlineRoot=[],0') super(i) end |
Instance Method Details
#bookmark(txt, level = 0, y = 0) ⇒ Object Also known as: Bookmark
#
bookmark
#
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pdf_paradise/fpdf/bookmark.rb', line 35 def bookmark(txt, level = 0, y = 0) y = self.GetY if y == -1 @outlines.push( { 't' => txt, 'l' => level, 'y' => y, 'p' => self.PageNo } ) end |
#putbookmarks ⇒ Object
#
putbookmarks
#
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/pdf_paradise/fpdf/bookmark.rb', line 50 def putbookmarks @nb = @outlines.size return if @nb == 0 lru=[] level=0 @outlines.each_index { |i| o = @outlines[i] if o['l']>0 parent=lru[o['l']-1] # Set parent and last pointers @outlines[i]['parent']=parent @outlines[parent]['last']=i if o['l']>level # Level increasing: set first pointer @outlines[parent]['first']=i end else @outlines[i]['parent']=@nb end if o['l']<=level and i>0 # Set prev and next pointers prev=lru[o['l']] @outlines[prev]['next']=i @outlines[i]['prev']=prev end lru[o['l']]=i level = o['l'] } # Outline items n=@n+1 @outlines.each_index do |i| o=@outlines[i] newobj out('<</Title '+(textstring(o['t']))) out('/Parent '+(n+o['parent']).to_s+' 0 R') if o['prev'] out('/Prev '+(n+o['prev']).to_s+' 0 R') end if o['next'] out('/Next '+(n+o['next']).to_s+' 0 R') end if o['first'] out('/First '+(n+o['first']).to_s+' 0 R') end if o['last'] out('/Last '+(n+o['last']).to_s+' 0 R') end out(sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]',1+2*o['p'],(@h-o['y'])*@k)) out('/Count 0>>') out('endobj') end # Outline root newobj @OutlineRoot=@n out('<</Type /Outlines /First '+n.to_s+' 0 R') out('/Last '+(n+lru[0]).to_s+' 0 R>>') out('endobj') end |
#putcatalog ⇒ Object
#
putcatalog
#
121 122 123 124 125 126 127 |
# File 'lib/pdf_paradise/fpdf/bookmark.rb', line 121 def putcatalog super if not @outlines.empty? out('/Outlines '+@OutlineRoot.to_s+' 0 R') out('/PageMode /UseOutlines') end end |
#putresources ⇒ Object
#
putresources
#
113 114 115 116 |
# File 'lib/pdf_paradise/fpdf/bookmark.rb', line 113 def putresources super putbookmarks end |