Method: RBPDF#RadioButton

Defined in:
lib/rbpdf.rb

#RadioButton(name, w, prop = {}, opt = {}, onvalue = 'On', checked = false, x = '', y = '', js = false) ⇒ Object Also known as: radio_button

Creates a RadioButton field

@param string :name

field name

@param int :w

width

@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 string :onvalue

value to be returned if selected.

@param boolean :checked

define the initial state.

@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)


10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
# File 'lib/rbpdf.rb', line 10917

def RadioButton(name, w, prop = {}, opt = {}, onvalue = 'On', checked = false, x = '', y = '', js = false)
  x = @x if x == ''
  y = @y if y == ''

  if js
    addfield('radiobutton', name, x, y, w, w, prop)
    return
  end

  onvalue = 'On' if empty_string(onvalue)
  defval = checked ? onvalue : 'Off'
  # set data for parent group
  @radiobutton_groups[@page] ||= {}
  unless @radiobutton_groups[@page][name]
    @radiobutton_groups[@page][name] = []
    @annot_obj_id += 1
    @radio_groups << @annot_obj_id
  end
  # save object ID to be added on Kids entry on parent object
  @radiobutton_groups[@page][name] << {'kid' => @annot_obj_id + 1, 'def' => defval}
  # get default style
  prop = getFormDefaultProp.merge prop
  prop['NoToggleToOff'] = 'true'
  prop['Radio'] = 'true'
  prop['borderStyle'] = 'inset'
  # get annotation data
  popt = getAnnotOptFromJSProp(prop)
  # set additional default values
  font = 'zapfdingbats'
  AddFont(font)
  fontkey = @fontkeys.index font
  unless @annotation_fonts.include? fontkey
    @annotation_fonts[font] = fontkey
  end
  fontstyle = sprintf('/F%d %.2f Tf', fontkey + 1, @font_size_pt)
  popt['da'] = "#{fontstyle} #{@text_color}"
  popt['ap'] = {}
  popt['ap']['n'] = {}
  popt['ap']['n'][onvalue] = "q #{@text_color} BT #{fontstyle} 0 0 Td (n) Tj ET Q"
  popt['ap']['n']['Off'] = "q #{@text_color} BT #{fontstyle} 0 0 Td (o) Tj ET Q"
  popt['mk'] ||= {}
  popt['mk']['ca'] = '(l)'
  # merge options
  opt = popt.merge opt
  # set remaining annotation data
  opt['Subtype'] = 'Widget'
  opt['ft'] = 'Btn'
  if checked
    opt['v'] = ["/#{onvalue}"]
    opt['as'] = onvalue
  else
    opt['as'] = 'Off'
  end
  Annotation(x, y, w, w, name, opt, 0)
  if @rtl
    @x -= w
  else
    @x += w
  end
end