Class: DynamicPDFApi::PageNumberingElement

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

Overview

Represents a page numbering label page element.

This class can be used to add page numbering to a PDF document. The following tokens can be used within the text of a PageNumberingLabel. They will be replaced with the appropriate value when the PDF is output. table All tokens except the /%/%PR/%/% token can also contain a numbering style specifier. The numbering style specifier is placed in parenthesis after the token. table There should be no spaces within a token, only the token and optional numbering style specifier. This token is invalid /%/%CP ( i )/%/% because of the extra spaces.Here are some examples of valid tokens: margin-top: 0px

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(text, placement = ElementPlacement::TOP_LEFT, x_offset = 0, y_offset = 0) ⇒ PageNumberingElement

Initializes a new instance of the PageNumberingElement class.

Parameters:

  • text (String)

    Text to display in the label.

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

    The placement of the page numbering element on the page.

  • x_offset (float) (defaults to: 0)

    X coordinate of the label.

  • y_offset (float) (defaults to: 0)

    Y coordinate of the label.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby_client/Elements/PageNumberingElement.rb', line 24

def initialize(text, placement= ElementPlacement::TOP_LEFT, x_offset = 0, y_offset = 0)
  @_font_name = nil
  @color = nil
  @font_size = nil

  @_text_font = nil
  @_resource = nil
  @_type = ElementType::PAGE_NUMBERING

  super(text, placement, x_offset, y_offset)
  @text = text
end

Instance Attribute Details

#_font_nameObject

Returns the value of attribute _font_name.



37
38
39
# File 'lib/ruby_client/Elements/PageNumberingElement.rb', line 37

def _font_name
  @_font_name
end

#colorObject

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



42
43
44
# File 'lib/ruby_client/Elements/PageNumberingElement.rb', line 42

def color
  @color
end

#font_sizeObject

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



47
48
49
# File 'lib/ruby_client/Elements/PageNumberingElement.rb', line 47

def font_size
  @font_size
end

#textObject

Gets or sets the text to display in the label.



52
53
54
# File 'lib/ruby_client/Elements/PageNumberingElement.rb', line 52

def text
  @text
end

Instance Method Details

#font(value) ⇒ Object

Gets or sets the Font object to use for the text of the label.



57
58
59
60
61
# File 'lib/ruby_client/Elements/PageNumberingElement.rb', line 57

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

#to_json(_options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ruby_client/Elements/PageNumberingElement.rb', line 63

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

  json_array['type'] = 'pageNumbering'

  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).gsub('\\\\', '\\').gsub('\"', '"').gsub('\\\r', '\r').gsub('\\\n', '\n').gsub('\\\t', '\t')
end