class HexaPDF::Type::AcroForm::VariableTextField
An AcroForm
variable text field defines how text that it is not known at generation time should be rendered. For example, AcroForm
text fields (normally) don't have an initial value; the value is entered by the user and needs to be rendered correctly by the PDF reader.
See: PDF1.7 s12.7.3.3
Constants
- INHERITABLE_FIELDS
All inheritable dictionary fields for text fields.
Public Instance Methods
Parses the default appearance string and returns an array containing [font_name, font_size].
The default appearance string is taken from the field or, if not set, the default appearance string of the form.
# File lib/hexapdf/type/acro_form/variable_text_field.rb, line 106 def parse_default_appearance_string da = self[:DA] || (document.acro_form && document.acro_form[:DA]) raise HexaPDF::Error, "No default appearance string set" unless da font_params = nil HexaPDF::Content::Parser.parse(da) do |obj, params| font_params = params.dup if obj == :Tf end font_params end
Sets the default appearance string using the provided values.
The default argument values are a sane default. If font_size
is set to 0, the font size is calculated using the height/width of the field.
# File lib/hexapdf/type/acro_form/variable_text_field.rb, line 95 def set_default_appearance_string(font: 'Helvetica', font_size: 0) name = document.acro_form(create: true).default_resources. add_font(document.fonts.add(font).pdf_object) self[:DA] = "0 g /#{name} #{font_size} Tf" end
Sets or returns the text alignment that should be used when displaying text.
With no argument, the current text alignment is returned. When a value is provided, the text alignment is set accordingly.
The alignment value is one of :left, :center or :right.
# File lib/hexapdf/type/acro_form/variable_text_field.rb, line 73 def text_alignment(alignment = UNSET_ARG) if alignment == UNSET_ARG case self[:Q] when 0 then :left when 1 then :center when 2 then :right end else self[:Q] = case alignment when :left then 0 when :center then 1 when :right then 2 else raise ArgumentError, "Invalid variable text field alignment #{alignment}" end end end