Method: RBPDF#ComboBox
- Defined in:
- lib/rbpdf.rb
#ComboBox(name, w, h, values, prop = {}, opt = {}, x = '', y = '', js = false) ⇒ Object Also known as: combo_box
Creates a Combo-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)
11081 11082 11083 11084 11085 11086 11087 11088 11089 11090 11091 11092 11093 11094 11095 11096 11097 11098 11099 11100 11101 11102 11103 11104 11105 11106 11107 11108 11109 11110 11111 11112 11113 11114 11115 11116 11117 11118 11119 11120 11121 11122 11123 11124 11125 11126 11127 11128 11129 11130 11131 11132 11133 11134 11135 11136 11137 11138 11139 11140 11141 11142 11143 11144 11145 11146 11147 11148 11149 11150 11151 |
# File 'lib/rbpdf.rb', line 11081 def ComboBox(name, w, h, values, prop = {}, opt = {}, x = '', y = '', js = false) x = @x if x == '' y = @y if y == '' if js addfield('combobox', 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 prop['Combo'] = 'true' # get annotation data popt = getAnnotOptFromJSProp(prop) # set additional default options 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 |