Method: PDF::QuickRef#initialize

Defined in:
lib/extensions/pdf-writer/pdf/quickref.rb

#initialize(paper = "LETTER", columns = 3, column_separators_visible = true) {|_self| ... } ⇒ QuickRef

Create the quick reference document. paper is passed unchanged to the PDF::Writer.new; the page is always created landscape. Margins are initialized to 18 points. After some additional initialization is performed, the quick reference document is yielded to an optional block for further configuration. All of this is done before the columns are started.

After the columns are started, lines will be drawn between column positions.

Yields:

  • (_self)

Yield Parameters:

  • _self (PDF::QuickRef)

    the object that the method was called on



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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/extensions/pdf-writer/pdf/quickref.rb', line 64

def initialize(paper = "LETTER", columns = 3, column_separators_visible = true)
  @pdf  = PDF::Writer.new(:paper => paper, :orientation => :landscape)
  @pdf.margins_pt 18
  @pdf.y = @pdf.absolute_top_margin

  @title_font       = "Times-Roman"
  @heading_font     = "Times-Roman"
  @body_font        = "Times-Roman"
  @code_font        = "Courier"
  @title_font_size = 14
  @h1_font_size    = 11
  @h2_font_size    =  9
  @h3_font_size    =  8
  @h4_font_size    =  7
  @body_font_size  =  6

  @ptab = PDF::SimpleTable.new do |tab|
    tab.column_order.replace %w(one two)

    tab.font_size     = @body_font_size
    tab.show_lines    = :none
    tab.show_headings = false
    tab.orientation   = :center
    tab.position      = :center
  end
  @ltab = PDF::SimpleTable.new do |tab|
    tab.column_order.replace %w(line)

    tab.font_size     = @body_font_size
    tab.show_lines    = :none
    tab.show_headings = false
    tab.orientation   = :center
    tab.position      = :center
  end

  yield self if block_given?

  @pdf.start_columns columns

  @ptab.font_size = @body_font_size
  @ltab.font_size = @body_font_size

  @ptab.maximum_width = @pdf.column_width - 10
  @ltab.maximum_width = @pdf.column_width - 10

  if column_separators_visible
    # Put lines between the columns.
    all = @pdf.open_object
    @pdf.save_state
    @pdf.stroke_color! Color::RGB::Black
    @pdf.stroke_style  PDF::Writer::StrokeStyle::DEFAULT
    (1 .. (columns - 1)).each do |ii|
      x = @pdf.left_margin + (@pdf.column_width * ii)
      x += (@pdf.column_gutter * (ii - 0.5))
      @pdf.line(x, @pdf.page_height - @pdf.top_margin, x, @pdf.bottom_margin)
      @pdf.stroke
    end
    @pdf.restore_state
    @pdf.close_object
    @pdf.add_object(all, :all_pages)
  end
end