dynamicpdf_api 1.0.0.pre.beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ruby_client/Action.rb +15 -0
  3. data/lib/ruby_client/AdditionalResource.rb +113 -0
  4. data/lib/ruby_client/AdditionalResourceType.rb +27 -0
  5. data/lib/ruby_client/Aes128Security.rb +70 -0
  6. data/lib/ruby_client/Aes256Security.rb +70 -0
  7. data/lib/ruby_client/Align.rb +21 -0
  8. data/lib/ruby_client/ButtonFieldInformation.rb +48 -0
  9. data/lib/ruby_client/ButtonFieldType.rb +16 -0
  10. data/lib/ruby_client/ChoiceFieldInformation.rb +52 -0
  11. data/lib/ruby_client/ChoiceFieldType.rb +16 -0
  12. data/lib/ruby_client/CmykColor.rb +47 -0
  13. data/lib/ruby_client/Color.rb +12 -0
  14. data/lib/ruby_client/ColorSpaceType.rb +36 -0
  15. data/lib/ruby_client/ConverterInput.rb +100 -0
  16. data/lib/ruby_client/DlexInput.rb +61 -0
  17. data/lib/ruby_client/DlexLayout.rb +135 -0
  18. data/lib/ruby_client/DlexResource.rb +40 -0
  19. data/lib/ruby_client/Elements/AztecBarcodeElement.rb +113 -0
  20. data/lib/ruby_client/Elements/AztecSymbolSize.rb +206 -0
  21. data/lib/ruby_client/Elements/BarcodeElement.rb +37 -0
  22. data/lib/ruby_client/Elements/Code11BarcodeElement.rb +77 -0
  23. data/lib/ruby_client/Elements/Code128BarcodeElement.rb +105 -0
  24. data/lib/ruby_client/Elements/Code25BarcodeElement.rb +75 -0
  25. data/lib/ruby_client/Elements/Code39BarcodeElement.rb +75 -0
  26. data/lib/ruby_client/Elements/Code93BarcodeElement.rb +75 -0
  27. data/lib/ruby_client/Elements/Compaction.rb +26 -0
  28. data/lib/ruby_client/Elements/DataMatrixBarcodeElement.rb +95 -0
  29. data/lib/ruby_client/Elements/DataMatrixEncodingType.rb +56 -0
  30. data/lib/ruby_client/Elements/DataMatrixFunctionCharacter.rb +31 -0
  31. data/lib/ruby_client/Elements/DataMatrixSymbolSize.rb +161 -0
  32. data/lib/ruby_client/Elements/Dim2BarcodeElement.rb +28 -0
  33. data/lib/ruby_client/Elements/Element.rb +46 -0
  34. data/lib/ruby_client/Elements/ElementPlacement.rb +36 -0
  35. data/lib/ruby_client/Elements/ElementType.rb +96 -0
  36. data/lib/ruby_client/Elements/ErrorCorrection.rb +56 -0
  37. data/lib/ruby_client/Elements/Gs1DataBarBarcodeElement.rb +76 -0
  38. data/lib/ruby_client/Elements/Gs1DataBarType.rb +22 -0
  39. data/lib/ruby_client/Elements/Iata25BarcodeElement.rb +83 -0
  40. data/lib/ruby_client/Elements/ImageElement.rb +108 -0
  41. data/lib/ruby_client/Elements/LineElement.rb +92 -0
  42. data/lib/ruby_client/Elements/MsiBarcodeCheckDigitMode.rb +31 -0
  43. data/lib/ruby_client/Elements/MsiBarcodeElement.rb +79 -0
  44. data/lib/ruby_client/Elements/PageNumberingElement.rb +91 -0
  45. data/lib/ruby_client/Elements/Pdf417BarcodeElement.rb +112 -0
  46. data/lib/ruby_client/Elements/QrCodeElement.rb +77 -0
  47. data/lib/ruby_client/Elements/QrCodeFnc1.rb +22 -0
  48. data/lib/ruby_client/Elements/RectangleElement.rb +109 -0
  49. data/lib/ruby_client/Elements/StackedGs1DataBarBarcodeElement.rb +90 -0
  50. data/lib/ruby_client/Elements/StackedGs1DataBarType.rb +23 -0
  51. data/lib/ruby_client/Elements/TextBarcodeElement.rb +48 -0
  52. data/lib/ruby_client/Elements/TextElement.rb +83 -0
  53. data/lib/ruby_client/Elements/ValueType.rb +16 -0
  54. data/lib/ruby_client/EncryptDocumentComponents.rb +16 -0
  55. data/lib/ruby_client/EndPointException.rb +7 -0
  56. data/lib/ruby_client/Endpoint.rb +38 -0
  57. data/lib/ruby_client/EndpointResource.rb +7 -0
  58. data/lib/ruby_client/ExcelInput.rb +49 -0
  59. data/lib/ruby_client/ExcelResource.rb +79 -0
  60. data/lib/ruby_client/Font.rb +276 -0
  61. data/lib/ruby_client/FontInformation.rb +9 -0
  62. data/lib/ruby_client/FontResource.rb +35 -0
  63. data/lib/ruby_client/FormField.rb +62 -0
  64. data/lib/ruby_client/FormFieldInformation.rb +45 -0
  65. data/lib/ruby_client/GoToAction.rb +53 -0
  66. data/lib/ruby_client/Grayscale.rb +41 -0
  67. data/lib/ruby_client/HtmlInput.rb +60 -0
  68. data/lib/ruby_client/HtmlResource.rb +34 -0
  69. data/lib/ruby_client/ImageInfo.rb +69 -0
  70. data/lib/ruby_client/ImageInformation.rb +57 -0
  71. data/lib/ruby_client/ImageInput.rb +150 -0
  72. data/lib/ruby_client/ImageResource.rb +89 -0
  73. data/lib/ruby_client/ImageResponse.rb +24 -0
  74. data/lib/ruby_client/Input.rb +53 -0
  75. data/lib/ruby_client/InputType.rb +41 -0
  76. data/lib/ruby_client/JsonResponse.rb +18 -0
  77. data/lib/ruby_client/LayoutDataResource.rb +48 -0
  78. data/lib/ruby_client/LineStyle.rb +79 -0
  79. data/lib/ruby_client/MergeOptions.rb +135 -0
  80. data/lib/ruby_client/MultiSelectListBoxInformation.rb +45 -0
  81. data/lib/ruby_client/Outline.rb +113 -0
  82. data/lib/ruby_client/OutlineList.rb +57 -0
  83. data/lib/ruby_client/OutlineStyle.rb +28 -0
  84. data/lib/ruby_client/OutputSize.rb +10 -0
  85. data/lib/ruby_client/PageInformation.rb +27 -0
  86. data/lib/ruby_client/PageInput.rb +152 -0
  87. data/lib/ruby_client/PageOrientation.rb +17 -0
  88. data/lib/ruby_client/PageSize.rb +127 -0
  89. data/lib/ruby_client/PageZoom.rb +33 -0
  90. data/lib/ruby_client/Pdf.rb +417 -0
  91. data/lib/ruby_client/PdfContent.rb +21 -0
  92. data/lib/ruby_client/PdfInfo.rb +68 -0
  93. data/lib/ruby_client/PdfInfoResponse.rb +27 -0
  94. data/lib/ruby_client/PdfInformation.rb +81 -0
  95. data/lib/ruby_client/PdfInput.rb +66 -0
  96. data/lib/ruby_client/PdfInstructions.rb +97 -0
  97. data/lib/ruby_client/PdfResource.rb +36 -0
  98. data/lib/ruby_client/PdfResponse.rb +23 -0
  99. data/lib/ruby_client/PdfText.rb +85 -0
  100. data/lib/ruby_client/PdfTextResponse.rb +27 -0
  101. data/lib/ruby_client/PdfXmp.rb +67 -0
  102. data/lib/ruby_client/PushButtonInformation.rb +21 -0
  103. data/lib/ruby_client/RC4128Security.rb +62 -0
  104. data/lib/ruby_client/Resource.rb +51 -0
  105. data/lib/ruby_client/ResourceType.rb +48 -0
  106. data/lib/ruby_client/Response.rb +39 -0
  107. data/lib/ruby_client/RgbColor.rb +1048 -0
  108. data/lib/ruby_client/Security.rb +73 -0
  109. data/lib/ruby_client/SecurityType.rb +23 -0
  110. data/lib/ruby_client/SignatureFieldInformation.rb +21 -0
  111. data/lib/ruby_client/Template.rb +46 -0
  112. data/lib/ruby_client/TextFieldInformation.rb +27 -0
  113. data/lib/ruby_client/TextReplace.rb +43 -0
  114. data/lib/ruby_client/UnitConverter.rb +111 -0
  115. data/lib/ruby_client/UrlAction.rb +31 -0
  116. data/lib/ruby_client/VAlign.rb +21 -0
  117. data/lib/ruby_client/WebColor.rb +18 -0
  118. data/lib/ruby_client/WordInput.rb +65 -0
  119. data/lib/ruby_client/WordResource.rb +82 -0
  120. data/lib/ruby_client/XmlResponse.rb +23 -0
  121. data/lib/ruby_client/version.rb +5 -0
  122. data/lib/ruby_client.rb +123 -0
  123. metadata +169 -0
@@ -0,0 +1,45 @@
1
+ module DynamicPDFApi
2
+ #
3
+ # Represents the form field information containing the collection of different types of field informations.
4
+ #
5
+ class FormFieldInformation
6
+ def initialize
7
+ @signature_fields = nil
8
+ @text_fields = nil
9
+ @choice_fields = nil
10
+ @button_fields = nil
11
+ @push_buttons = nil
12
+ @multi_select_list_box_fields = nil
13
+ end
14
+
15
+ #
16
+ # Gets or sets a collection of SignatureFieldInformation.
17
+ #
18
+ attr_accessor :signature_fields
19
+
20
+ #
21
+ # Gets or sets a collection of TextFieldInformation.
22
+ #
23
+ attr_accessor :text_fields
24
+
25
+ #
26
+ # Gets or sets a collection of ChoiceFieldInformation.
27
+ #
28
+ attr_accessor :choice_fields
29
+
30
+ #
31
+ # Gets or sets a collection of ButtonFieldInformation.
32
+ #
33
+ attr_accessor :button_fields
34
+
35
+ #
36
+ # Gets or sets a collection of PushButtonInformation.
37
+ #
38
+ attr_accessor :push_buttons
39
+
40
+ #
41
+ # Gets or sets a collection of MultiSelectListBoxInformation.
42
+ #
43
+ attr_accessor :multi_select_list_box_fields
44
+ end
45
+ end
@@ -0,0 +1,53 @@
1
+ module DynamicPDFApi
2
+ require_relative 'Action'
3
+ require_relative 'Input'
4
+ require_relative 'PageZoom'
5
+
6
+ #
7
+ # Represents a goto action in a PDF document that navigates to a specific page using page number and zoom
8
+ # options.
9
+ #
10
+ class GoToAction < Action
11
+ #
12
+ # Initializes a new instance of the GoToAction class using an input to create the PDF, page number, and
13
+ # a zoom option.
14
+ #
15
+ # @param input [Input] Any of the ImageInput, DlexInput, PdfInput or PageInput objects to create PDF.
16
+ # @param page_offset [int] Page number to navigate.
17
+ # @param page_zoom [String] PageZoom to display the destination.
18
+ #
19
+ def initialize(input, page_offset = 0, page_zoom = PageZoom::FIT_PAGE)
20
+ super()
21
+ @_input = input
22
+ @_input_id = input.id
23
+ @page_offset = page_offset
24
+ @page_zoom = page_zoom
25
+ end
26
+
27
+ attr_accessor :_input, :_input_id
28
+
29
+ #
30
+ # Gets or sets page Offset.
31
+ #
32
+ attr_accessor :page_offset
33
+
34
+ #
35
+ # Gets or sets PageZoom to display the destination.
36
+ #
37
+ attr_accessor :page_zoom
38
+
39
+ def to_json(_options = {})
40
+ json_array = {}
41
+
42
+ json_array['input'] = @_input unless @_input.nil?
43
+
44
+ json_array['inputID'] = @_input_id unless @_input_id.nil?
45
+
46
+ json_array['pageOffset'] = @page_offset unless @page_offset.nil?
47
+
48
+ json_array['pageZoom'] = @page_zoom unless @page_zoom.nil?
49
+
50
+ JSON.pretty_generate(json_array)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,41 @@
1
+ module DynamicPDFApi
2
+ require_relative "Color"
3
+
4
+ #
5
+ # Represents a grayscale color.
6
+ #
7
+ class Grayscale < Color
8
+ #
9
+ # Initializes a new instance of the Grayscale class.
10
+ #
11
+ # @param gray_level [float] The gray level for the color.
12
+ #
13
+ def initialize(gray_level = 0)
14
+ super()
15
+ @gray_level = gray_level
16
+ @_color_string = "gray(#{gray_level})"
17
+ end
18
+
19
+ def self.create_grayscale(gray_level)
20
+ gray_scale = Grayscale.new
21
+ gray_scale._color_string = gray_level
22
+ gray_scale
23
+ end
24
+
25
+ #
26
+ # Gets the color black.
27
+ #
28
+ def self.black
29
+ Grayscale.new(0)
30
+ end
31
+
32
+ #
33
+ # Gets the color white.
34
+ #
35
+ def self.white
36
+ Grayscale.new(1)
37
+ end
38
+
39
+ attr_accessor :_color_string
40
+ end
41
+ end
@@ -0,0 +1,60 @@
1
+ module DynamicPDFApi
2
+ require_relative "UnitConverter"
3
+ #
4
+ # Represents a html input.
5
+ #
6
+ class HtmlInput < ConverterInput
7
+
8
+ #
9
+ # Initializes a new instance of the HtmlInput class.
10
+ #
11
+ # @param resource [HtmlResource] The resource of type HtmlResource.
12
+ # @param base_path [string] The base_path options for the url.
13
+ # @param size [PageSize] The page size of the output PDF.
14
+ # @param orientation [PageOrientation] The page orientation of the output PDF.
15
+ # @param margins [float] The page margins of the output PDF.
16
+ def initialize(resource, base_path = nil, size = PageSize::LETTER, orientation = PageOrientation::PORTRAIT, margins = nil)
17
+ super(resource, size, orientation, margins)
18
+
19
+ @_type = InputType::HTML
20
+
21
+ if (base_path != nil)
22
+ @base_path = base_path
23
+ end
24
+ end
25
+
26
+ #
27
+ # Gets or sets the base path option.
28
+ #
29
+ attr_accessor :base_path
30
+
31
+ def to_json(_options = {})
32
+ json_array = {}
33
+
34
+ json_array["type"] = "html"
35
+
36
+ json_array["basePath"] = @scale_x unless @scale_x.nil?
37
+
38
+ json_array["topMargin"] = @top_margin unless @top_margin.nil?
39
+
40
+ json_array["leftMargin"] = @left_margin unless @left_margin.nil?
41
+
42
+ json_array["bottomMargin"] = @bottom_margin unless @bottom_margin.nil?
43
+
44
+ json_array["rightMargin"] = @right_margin unless @right_margin.nil?
45
+
46
+ json_array["pageWidth"] = @page_width unless @page_width.nil?
47
+
48
+ json_array["pageHeight"] = @page_height unless @page_height.nil?
49
+
50
+ #---------------------------------------------------
51
+ json_array["templateId"] = @_template_id unless @_template_id.nil?
52
+
53
+ json_array["resourceName"] = @resource_name unless @resource_name.nil?
54
+
55
+ json_array["id"] = @id unless @id.nil?
56
+
57
+ JSON.pretty_generate(json_array)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,34 @@
1
+ module DynamicPDFApi
2
+ #
3
+ # Represents a pdf resource.
4
+ #
5
+ class HtmlResource < Resource
6
+
7
+ #
8
+ # Initializes a new instance of the HtmlResource class.
9
+ #
10
+ # @param name="html">The input html string.
11
+ # @param name="resourceName">The name of the resource.
12
+ def initialize(html, resourceName = nil)
13
+ @_file_extension = ".html"
14
+ @_mime_type = "text/html"
15
+
16
+ @data = html
17
+
18
+ @resource_name = if resource_name.nil?
19
+ SecureRandom.uuid + @_file_extension
20
+ else
21
+ resource_name
22
+ end
23
+ _type = ResourceType::HTML
24
+ end
25
+
26
+ def to_json(_options = {})
27
+ json_array = {}
28
+ json_array["type"] = "html"
29
+
30
+ json_array["resourceName"] = @resource_name
31
+ JSON.pretty_generate(json_array)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,69 @@
1
+ module DynamicPDFApi
2
+ require_relative 'Endpoint'
3
+ require_relative 'ImageResponse'
4
+
5
+ #
6
+ # Represents an image information endpoint.
7
+ #
8
+ class ImageInfo < Endpoint
9
+ #
10
+ # Initializes a new instance of the ImageInfo class.
11
+ #
12
+ # ImageResource resource The image resource of type ImageResource.
13
+ #
14
+ def initialize(resource)
15
+ @_endpoint_name = 'image-info'
16
+ super()
17
+ @resource = resource
18
+ end
19
+
20
+ #
21
+ # Process the image resource to get image's information.
22
+ #
23
+ # @return ImageResponse Returns collection of ImageResponse.
24
+ #
25
+ def process
26
+ header = {
27
+ 'Authorization': "Bearer #{@api_key}",
28
+ 'Content-Length': @resource.data.length.to_s,
29
+ 'Expect': '100-continue',
30
+ 'Content-Type': "image/#{@resource._file_extension[1, @resource._file_extension.length - 1]}"
31
+ }
32
+ uri = URI.parse("#{@base_url}/v1.0/#{@_endpoint_name}")
33
+
34
+ request = Net::HTTP::Post.new(uri.request_uri, header)
35
+
36
+ req_options = {
37
+ use_ssl: uri.scheme == 'https',
38
+ verify_mode: OpenSSL::SSL::VERIFY_NONE
39
+
40
+ }
41
+
42
+ request.content_type = "image/#{@resource._file_extension[1, @resource._file_extension.length - 1]}"
43
+
44
+ request.body = @resource.data
45
+
46
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
47
+ http.request(request)
48
+ end
49
+ out_data = response.body
50
+ ret_object = ImageResponse.new(out_data)
51
+ ret_object.is_successful = false
52
+ ret_object.status_code = response.code
53
+ if ret_object.status_code == '200'
54
+ ret_object.is_successful = true
55
+ else
56
+ out_data_json = JSON.parse(out_data)
57
+ ret_object.error_json = out_data
58
+ ret_object.error_message = if !out_data_json['message'].nil?
59
+ out_data_json['message']
60
+ else
61
+ "status_code : #{Net::HTTPResponse::CODE_TO_OBJ[ret_object.status_code]}"
62
+ end
63
+ ret_object.error_id = out_data_json['id']
64
+ end
65
+
66
+ ret_object
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,57 @@
1
+ module DynamicPDFApi
2
+ #
3
+ # Represents an image information.
4
+ #
5
+ class ImageInformation
6
+ def initialize(_resource)
7
+ @page_number = nil
8
+ @width = nil
9
+ @height = nil
10
+ @horizontal_dpi = nil
11
+ @vertical_dpi = nil
12
+ @number_of_components = nil
13
+ @bits_per_component = nil
14
+ @color_space = nil
15
+ end
16
+
17
+ #
18
+ # Gets page number of the pdf where the image is present.
19
+ #
20
+ attr_accessor :page_number
21
+
22
+ #
23
+ # Gets the width of the image.
24
+ #
25
+ attr_accessor :width
26
+
27
+ #
28
+ # Gets the height of the image.
29
+ #
30
+ attr_accessor :height
31
+
32
+ #
33
+ # Gets the horizontalDpi of the image.
34
+ #
35
+ attr_accessor :horizontal_dpi
36
+
37
+ #
38
+ # Gets the verticalDpi of the image.
39
+ #
40
+ attr_accessor :vertical_dpi
41
+
42
+ #
43
+ # Gets the number of color components present in the image.
44
+ #
45
+ attr_accessor :number_of_components
46
+
47
+ #
48
+ # Gets the bits per component of the image.
49
+ #
50
+ attr_accessor :bits_per_component
51
+
52
+ #
53
+ # Gets the color space of the image.
54
+ #
55
+ attr_accessor :color_space
56
+ end
57
+ end
@@ -0,0 +1,150 @@
1
+ module DynamicPDFApi
2
+ require_relative 'Input'
3
+ require_relative 'ImageResource'
4
+ require_relative 'InputType'
5
+ require_relative 'Align'
6
+ require_relative 'VAlign'
7
+
8
+ #
9
+ # Represents an image input.
10
+ #
11
+ class ImageInput < Input
12
+ #
13
+ # Initializes a new instance of the ImageInput class.
14
+ #
15
+ # @param resource [String]|[ImageResource] The image file path present in cloud resource manager or the ImageResource object to create ImageInput.
16
+ #
17
+ def initialize(resource)
18
+ @_type = InputType::IMAGE
19
+ @scale_x = nil
20
+ @scale_y = nil
21
+ @top_margin = nil
22
+ @left_margin = nil
23
+ @bottom_margin = nil
24
+ @right_margin = nil
25
+ @page_width = nil
26
+ @page_height = nil
27
+ @expand_to_fit = nil
28
+ @shrink_to_fit = nil
29
+ @align = Align::CENTER
30
+ @v_align = VAlign::CENTER
31
+ @start_page = nil
32
+ @page_count = nil
33
+ super(resource)
34
+ end
35
+
36
+ attr_accessor :_type
37
+
38
+ #
39
+ # Gets or sets the scaleX of the image.
40
+ #
41
+ attr_accessor :scale_x
42
+
43
+ #
44
+ # Gets or sets the scaleY of the image.
45
+ #
46
+ attr_accessor :scale_y
47
+ #
48
+ # Gets or sets the top margin.
49
+ #
50
+ attr_accessor :top_margin
51
+
52
+ #
53
+ # Gets or sets the left margin.
54
+ #
55
+ attr_accessor :left_margin
56
+
57
+ #
58
+ # Gets or sets the bottom margin.
59
+ #
60
+ attr_accessor :bottom_margin
61
+
62
+ #
63
+ # Gets or sets the right margin.
64
+ #
65
+ attr_accessor :right_margin
66
+
67
+ #
68
+ # Gets or sets the page width.
69
+ #
70
+ attr_accessor :page_width
71
+
72
+ #
73
+ # Gets or sets the page height.
74
+ #
75
+ attr_accessor :page_height
76
+
77
+ #
78
+ # Gets or sets a boolean indicating whether to expand the image.
79
+ #
80
+ attr_accessor :expand_to_fit
81
+
82
+ #
83
+ # Gets or sets a boolean indicating whether to shrink the image.
84
+ #
85
+ attr_accessor :shrink_to_fit
86
+
87
+ #
88
+ # Gets or sets the horizontal alignment of the image.
89
+ #
90
+ attr_accessor :align
91
+
92
+ #
93
+ # Gets or sets the vertical alignment of the image.
94
+ #
95
+ attr_accessor :v_align
96
+
97
+ #
98
+ # Gets or sets the start page.
99
+ #
100
+ attr_accessor :start_page
101
+
102
+ #
103
+ # Gets or sets the page count.
104
+ #
105
+ attr_accessor :page_count
106
+
107
+ def to_json(_options = {})
108
+ json_array = {}
109
+
110
+ json_array['type'] = 'image'
111
+
112
+ json_array['scaleX'] = @scale_x unless @scale_x.nil?
113
+
114
+ json_array['scaleY'] = @scale_y unless @scale_y.nil?
115
+
116
+ json_array['topMargin'] = @top_margin unless @top_margin.nil?
117
+
118
+ json_array['leftMargin'] = @left_margin unless @left_margin.nil?
119
+
120
+ json_array['bottomMargin'] = @bottom_margin unless @bottom_margin.nil?
121
+
122
+ json_array['rightMargin'] = @right_margin unless @right_margin.nil?
123
+
124
+ json_array['pageWidth'] = @page_width unless @page_width.nil?
125
+
126
+ json_array['pageHeight'] = @page_height unless @page_height.nil?
127
+
128
+ json_array['expandToFit'] = @expand_to_fit unless @expand_to_fit.nil?
129
+
130
+ json_array['shrinkToFit'] = @shrink_to_fit unless @shrink_to_fit.nil?
131
+
132
+ json_array['align'] = @align unless @align.nil?
133
+
134
+ json_array['vAlign'] = @a_align unless @a_align.nil?
135
+
136
+ json_array['startPage'] = @start_page unless @start_page.nil?
137
+
138
+ json_array['pageCount'] = @page_count unless @page_count.nil?
139
+
140
+ #---------------------------------------------------
141
+ json_array['templateId'] = @_template_id unless @_template_id.nil?
142
+
143
+ json_array['resourceName'] = @resource_name unless @resource_name.nil?
144
+
145
+ json_array['id'] = @id unless @id.nil?
146
+
147
+ JSON.pretty_generate(json_array)
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,89 @@
1
+ module DynamicPDFApi
2
+ require_relative "Resource"
3
+ require_relative "ResourceType"
4
+ require_relative "EndPointException"
5
+
6
+ #
7
+ # Represents an image resource used to create an ImageInput object to create PDF from images.
8
+ #
9
+ class ImageResource < Resource
10
+ #
11
+ # Initializes a new instance of the ImageResource class.
12
+ #
13
+ # @param file [String]|[Stream] The image file path or the byte of the image file or the stream of the image file.
14
+ # @param resource_name [String] The name of the resource.
15
+ #
16
+ def initialize(file, resource_name = nil)
17
+ @_type = ResourceType::IMAGE
18
+ @_mime_type = nil
19
+ super(file, resource_name)
20
+ end
21
+
22
+ def _file_extension
23
+ @file_header = @data[0, 16]
24
+ @file_header = @file_header.bytes
25
+
26
+ if ImageResource.is_png_image(@file_header)
27
+ @_mime_type = "image/png"
28
+ ".png"
29
+ elsif ImageResource.is_jpeg_image(@file_header)
30
+ @_mime_type = "image/jpeg"
31
+ ".jpeg"
32
+ elsif ImageResource.is_gif_image(@file_header)
33
+ @_mime_type = "image/gif"
34
+ ".gif"
35
+ elsif ImageResource.is_tiff_image(@file_header)
36
+ @_mime_type = "image/tiff"
37
+ ".tiff"
38
+ elsif ImageResource.is_jpeg2000_image(@file_header)
39
+ @_mime_type = "image/jpeg"
40
+ ".jpeg"
41
+ elsif ImageResource.is_valid_bitmap_image(@file_header)
42
+ @_mime_type = "image/bmp"
43
+ ".bmp"
44
+ else
45
+ raise "Not supported image type or invalid image."
46
+ end
47
+ end
48
+
49
+ def self.is_jpeg2000_image(header)
50
+ (header[0] == 0x00 && header[1] == 0x00 && header[2] == 0x00 && header[3] == 0x0C && header[4] == 0x6A &&
51
+ header[5] == 0x50 && (header[6] == 0x1A || header[6] == 0x20) && (header[7] == 0x1A || header[7] == 0x20) &&
52
+ header[8] == 0x0D && header[9] == 0x0A && header[10] == 0x87 && header[11] == 0x0A) ||
53
+ (header[0] == 0xFF && header[1] == 0x4F && header[2] == 0xFF && header[3] == 0x51 && header[6] == 0x00 && header[7] == 0x00)
54
+ end
55
+
56
+ def self.is_png_image(header)
57
+ header[0] == 0x89 && header[1] == 0x50 && header[2] == 0x4E && header[3] == 0x47 &&
58
+ header[4] == 0x0D && header[5] == 0x0A && header[6] == 0x1A && header[7] == 0x0A
59
+ end
60
+
61
+ def self.is_tiff_image(header)
62
+ (header[0] == 0x49 && header[1] == 0x49 && header[2] == 0x2A && header[3] == 0x00) ||
63
+ (header[0] == 0x4D && header[1] == 0x4D && header[2] == 0x00 && header[3] == 0x2A)
64
+ end
65
+
66
+ def self.is_gif_image(header)
67
+ header[0] == 0x47 && header[1] == 0x49 && header[2] == 0x46 && header[3] == 0x38 && (header[4] == 0x37 ||
68
+ header[4] == 0x39) && header[5] == 0x61
69
+ end
70
+
71
+ def self.is_jpeg_image(header)
72
+ header[0] == 0xFF && header[1] == 0xD8 && header[2] == 0xFF
73
+ end
74
+
75
+ def self.is_valid_bitmap_image(header)
76
+ header[0] == 0x42 && header[1] == 0x4D
77
+ end
78
+
79
+ def to_json(_options = {})
80
+ json_array = {}
81
+ json_array["type"] = "image"
82
+ json_array["align"] = 1
83
+ json_array["vAlign"] = 1
84
+
85
+ json_array["resourceName"] = @resource_name
86
+ JSON.pretty_generate(json_array)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,24 @@
1
+ module DynamicPDFApi
2
+ require_relative 'JsonResponse'
3
+
4
+ #
5
+ # Represents an image response.
6
+ #
7
+ class ImageResponse < JsonResponse
8
+ #
9
+ # Initializes a new instance of the ImageResponse class.
10
+ #
11
+ # @param json_content [String] The image content of the response.
12
+ #
13
+ def initialize(json_content = nil)
14
+ @content = nil
15
+ super(json_content) unless json_content.nil?
16
+ @content = JSON.parse(json_content)
17
+ end
18
+
19
+ #
20
+ # Gets or sets a collection of ImageInformation.
21
+ #
22
+ attr_accessor :content
23
+ end
24
+ end
@@ -0,0 +1,53 @@
1
+ module DynamicPDFApi
2
+ require_relative 'InputType'
3
+ require_relative 'Resource'
4
+
5
+ #
6
+ # Represents the base class for inputs.
7
+ #
8
+ class Input
9
+ def initialize(resource = nil)
10
+ @_resources = []
11
+ @template = nil
12
+ @_type = nil
13
+ @_template_id = nil
14
+
15
+ if resource.is_a?(String)
16
+ @resource_name = resource
17
+ elsif !resource.nil?
18
+ @_resources << resource
19
+ @resource_name = resource.resource_name
20
+ end
21
+
22
+ @id = SecureRandom.uuid
23
+ end
24
+
25
+ attr_accessor :_type, :_template_id, :_resources
26
+
27
+ #
28
+ # Gets or sets the resource name.
29
+ #
30
+ attr_accessor :resource_name
31
+
32
+ #
33
+ # Gets or sets the id.
34
+ #
35
+ attr_accessor :id
36
+
37
+ #
38
+ # Gets or sets the template.
39
+ #
40
+ def set_template(template)
41
+ @template = template
42
+ @_template_id = template.id
43
+ end
44
+
45
+ def get_template
46
+ @template
47
+ end
48
+
49
+ def to_json(_options = {})
50
+ JSON.pretty_generate({})
51
+ end
52
+ end
53
+ end