Module: PDF_Bookmark
- Defined in:
- vendor/plugins/rfpdf/lib/rfpdf/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
Instance Method Summary
- - (Object) Bookmark(txt, level = 0, y = 0)
- - (Object) putbookmarks
- - (Object) putcatalog
- - (Object) putresources
Class Method Details
+ (Object) extend_object(o)
17 18 19 20 |
# File 'vendor/plugins/rfpdf/lib/rfpdf/bookmark.rb', line 17 def PDF_Bookmark.extend_object(o) o.instance_eval('@outlines,@OutlineRoot=[],0') super(o) end |
Instance Method Details
- (Object) Bookmark(txt, level = 0, y = 0)
22 23 24 25 |
# File 'vendor/plugins/rfpdf/lib/rfpdf/bookmark.rb', line 22 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 |
- (Object) putbookmarks
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 |
# File 'vendor/plugins/rfpdf/lib/rfpdf/bookmark.rb', line 27 def putbookmarks @nb=@outlines.size return if @nb==0 lru=[] level=0 @outlines.each_index do |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'] end # 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 |
- (Object) putcatalog
92 93 94 95 96 97 98 |
# File 'vendor/plugins/rfpdf/lib/rfpdf/bookmark.rb', line 92 def putcatalog super if not @outlines.empty? out('/Outlines '+@OutlineRoot.to_s+' 0 R') out('/PageMode /UseOutlines') end end |
- (Object) putresources
87 88 89 90 |
# File 'vendor/plugins/rfpdf/lib/rfpdf/bookmark.rb', line 87 def putresources super putbookmarks end |