Class: DynamicPDFApi::TextElement

Inherits:
Element
  • Object
show all
Defined in:
lib/ruby_client/Elements/TextElement.rb

Overview

Represents a text element.

This class can be used to place text on a page.

Instance Attribute Summary collapse

Attributes inherited from Element

#_input_value, #_resource, #_text_font, #_type, #even_pages, #odd_pages, #placement, #x_offset, #y_offset

Instance Method Summary collapse

Constructor Details

#initialize(value, placement = ElementPlacement::TOP_LEFT, x_offset = 0, y_offset = 0) ⇒ TextElement

Initializes a new instance of the TextElement class.

Parameters:

  • value (String)

    Text to display in the text element.

  • placement (String) (defaults to: ElementPlacement::TOP_LEFT)

    The placement of the text element on the page.

  • x_offset (float) (defaults to: 0)

    X coordinate of the text element.

  • y_offset (float) (defaults to: 0)

    Y coordinate of the text element.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby_client/Elements/TextElement.rb', line 19

def initialize(value, placement = ElementPlacement::TOP_LEFT, x_offset = 0, y_offset = 0)
  @_resource = nil
  @_text_font = nil
  @_font_name = nil

  @color = nil
  @font_size = nil
  @_type = ElementType::TEXT
  super(value, placement, x_offset, y_offset)
  @text = value
end

Instance Attribute Details

#colorObject

Gets or sets the Color object to use for the text of the text element.



34
35
36
# File 'lib/ruby_client/Elements/TextElement.rb', line 34

def color
  @color
end

#font_sizeObject

Gets or sets the font size for the text of the text element.



39
40
41
# File 'lib/ruby_client/Elements/TextElement.rb', line 39

def font_size
  @font_size
end

#textObject

Gets or sets the text to display in the text element.



44
45
46
# File 'lib/ruby_client/Elements/TextElement.rb', line 44

def text
  @text
end

Instance Method Details

#font(value) ⇒ Object

Gets or sets the Font object used to specify the font of the text for the text element.



49
50
51
52
53
# File 'lib/ruby_client/Elements/TextElement.rb', line 49

def font(value)
  @_text_font = value
  @_font_name = @_text_font._name
  @_resource = @_text_font._resource
end

#to_json(_options = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ruby_client/Elements/TextElement.rb', line 55

def to_json(_options = {})
  json_array = {}

  json_array["type"] = "text"

  json_array["font"] = @_font_name unless @_font_name.nil?

  json_array["text"] = @text

  json_array["color"] = @color._color_string if !@color.nil? && !@color._color_string.nil?

  json_array["fontSize"] = @font_size unless @font_size.nil?

  # ---------------------------------

  json_array["placement"] = @placement unless @placement.nil?

  json_array["xOffset"] = @x_offset unless @x_offset.nil?

  json_array["yOffset"] = @y_offset unless @y_offset.nil?

  json_array["evenPages"] = @even_pages unless @even_pages.nil?

  json_array["oddPages"] = @odd_pages unless @odd_pages.nil?

  JSON.pretty_generate(json_array)
end