Class: DynamicPDFApi::PageInput

Inherits:
Input
  • Object
show all
Defined in:
lib/ruby_client/PageInput.rb

Overview

Represents a page input.

Instance Attribute Summary collapse

Attributes inherited from Input

#_resources, #_template_id, #id, #resource_name

Instance Method Summary collapse

Methods inherited from Input

#get_template, #set_template

Constructor Details

#initialize(size = nil, orientation = nil, margins = nil) ⇒ PageInput

Initializes a new instance of the PageInput class.

Parameters:

  • size (String) (defaults to: nil)

    | [Float] The size of the page or The width of the page.

  • orientation (String) (defaults to: nil)

    | [Float] The orientation of the page or The height of the page.

  • margins (Float) (defaults to: nil)

    The margins of the page.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby_client/PageInput.rb', line 16

def initialize(size = nil, orientation = nil, margins = nil)
  super()
  @_resources = []
  @elements = []
  @_type = InputType::PAGE

  if (size.is_a?(String) && orientation.is_a?(String))
    if (size != nil)
      self.page_size = size
    end
    if (orientation != nil)
      self.page_orientation = orientation
    end

    if (margins != nil)
      @top_margin = margins
      @bottom_margin = margins
      @right_margin = margins
      @left_margin = margins
    end
  elsif (size.is_a?(Float) || size.is_a?(Integer))
      @page_width = size
      @page_height = orientation
  end
end

Instance Attribute Details

#_typeObject

Returns the value of attribute _type.



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

def _type
  @_type
end

#bottom_marginObject

Gets or sets the bottom margin.



67
68
69
# File 'lib/ruby_client/PageInput.rb', line 67

def bottom_margin
  @bottom_margin
end

#elementsObject

Returns the value of attribute elements.



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

def elements
  @elements
end

#left_marginObject

Gets or sets the left margin.



62
63
64
# File 'lib/ruby_client/PageInput.rb', line 62

def left_margin
  @left_margin
end

#page_heightObject

Gets or sets the height of the page.



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

def page_height
  @page_height
end

#page_widthObject

Gets or sets the width of the page.



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

def page_width
  @page_width
end

#right_marginObject

Gets or sets the right margin.



72
73
74
# File 'lib/ruby_client/PageInput.rb', line 72

def right_margin
  @right_margin
end

#top_marginObject

Gets or sets the top margin.



57
58
59
# File 'lib/ruby_client/PageInput.rb', line 57

def top_margin
  @top_margin
end

Instance Method Details

#get_elementsObject

Gets or sets the elements of the page.

Returns:

  • array Elements of the page.



120
121
122
# File 'lib/ruby_client/PageInput.rb', line 120

def get_elements
  @elements
end

#page_orientation=(value) ⇒ Object

Gets or sets page orientation.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/ruby_client/PageInput.rb', line 94

def page_orientation=(value)
  @page_orientation = value

  if(@page_width != nil && @page_height != nil)
    if @page_width > @page_height
      @smaller = @page_height
      @larger_Width = @page_width
    else
      @smaller = @page_width
      @larger_width = @page_height
    end

    if @page_orientation == PageOrientation::LANDSCAPE
      @page_height = @smaller
      @page_width = @larger_width
    else
      @page_height = @larger_width
      @page_width = @smaller
    end
  end
end

#page_size=(value) ⇒ Object

Gets or sets the Page size.



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ruby_client/PageInput.rb', line 77

def page_size=(value)
  @page_size = value

  @output_size = UnitConverter.get_paper_size(value)

  if @page_orientation == PageOrientation::LANDSCAPE
    @page_height = @output_size.smaller
    @page_width = @output_size.larger
  else
    @page_height = @output_size.larger
    @page_width = @output_size.smaller
  end
end

#to_json(_options = {}) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ruby_client/PageInput.rb', line 124

def to_json(_options = {})
  json_element = []
  @elements.each do |element|
    json_element << element unless element.nil?
  end

  json_array = {}

  json_array["type"] = "page"

  json_array["pageWidth"] = @page_width unless @page_width.nil?

  json_array["pageHeight"] = @page_height unless @page_height.nil?

  json_array["topMargin"] = @top_margin unless @top_margin.nil?

  json_array["leftMargin"] = @left_margin unless @left_margin.nil?

  json_array["bottomMargin"] = @bottom_margin unless @bottom_margin.nil?

  json_array["rightMargin"] = @right_margin unless @right_margin.nil?

  json_array["elements"] = json_element

  #---------------------------------------------------
  json_array["templateId"] = @_template_id unless @_template_id.nil?

  json_array["resourceName"] = @resource_name unless @resource_name.nil?

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

  JSON.pretty_generate(json_array)
end