Method: RBPDF#ListBox

Defined in:
lib/rbpdf.rb

#ListBox(name, w, h, values, prop = {}, opt = {}, x = '', y = '', js = false) ⇒ Object Also known as: list_box

Creates a List-box field

@param string :name

field name

@param int :w

width

@param int :h

height

@param array :values

array containing the list of values.

@param array :prop

javascript field properties. Possible values are described on official Javascript for Acrobat API reference.

@param array :opt

annotation parameters. Possible values are described on official PDF32000_2008 reference.

@param float :x

Abscissa of the upper-left corner of the rectangle

@param float :y

Ordinate of the upper-left corner of the rectangle

@param boolean :js

if true put the field using JavaScript (requires Acrobat Writer to be rendered).

@access public
@author Nicola Asuni
@since 4.8.000 (2009-09-07)


10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
# File 'lib/rbpdf.rb', line 10994

def ListBox(name, w, h, values, prop = {}, opt = {}, x = '', y = '', js = false)
  x = @x if x == ''
  y = @y if y == ''

  if js
    addfield('listbox', name, x, y, w, h, prop)
    s = +''
    values.each {|v|
      if v.is_a?(Array)
        s << "['#{v[0]}','#{v[1]}'],"
      else
        s << "'#{v}',"
      end
    }
    @javascript << "f#{name}.setItems([#{s[0...-1]}]);\n"
    return
  end
  # get default style
  prop = getFormDefaultProp.merge prop
  # get annotation data
  popt = getAnnotOptFromJSProp(prop)
  # set additional default values
  font = @font_family
  fontkey = @fontkeys.index font
  unless @annotation_fonts.include? fontkey
    @annotation_fonts[font] = fontkey
  end
  s = +''
  values.each {|v|
    if v.is_a?(Array)
      s << "#{v[1]}\n"
    else
      s << "#{v}\n"
    end
  }

  fontstyle = sprintf('/F%d %.2f Tf %s', fontkey + 1, @font_size_pt, @text_color)
  popt['da'] = fontstyle
  popt['ap'] = {}
  # set Appearances
  popt['ap']['n'] = +"/Tx BMC q #{fontstyle} "
  gvars = getGraphicVars()
  @h = h
  @w = w
  @t_margin = 0
  @c_margin = 0.2

  @tmp_buffer = +''
  multi_cell(w, h, s, 0, '', 0, 0, 0.2, 0, true, 0, false, true, 0)
  popt['ap']['n'] << @tmp_buffer
  popt['ap']['n'] << 'Q EMC'
  @tmp_buffer = nil

  # restore previous values
  setGraphicVars(gvars, true)

  # merge options
  opt = popt.merge opt
  # set remaining annotation data
  opt['Subtype'] = 'Widget'
  opt['ft'] = 'Ch'
  opt['t'] = name
  opt['opt'] = values
  Annotation(x, y, w, h, name, opt, 0)
  if @rtl
    @x -= w
  else
    @x += w
  end
end