dynamicpdf_api 1.0.1 → 1.1.1

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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ruby_client/Elements/AztecBarcodeElement.rb +6 -10
  3. data/lib/ruby_client/Elements/Code11BarcodeElement.rb +3 -5
  4. data/lib/ruby_client/Elements/Code128BarcodeElement.rb +7 -11
  5. data/lib/ruby_client/Elements/Code25BarcodeElement.rb +3 -5
  6. data/lib/ruby_client/Elements/Code39BarcodeElement.rb +4 -5
  7. data/lib/ruby_client/Elements/Code93BarcodeElement.rb +3 -5
  8. data/lib/ruby_client/Elements/DataMatrixBarcodeElement.rb +4 -7
  9. data/lib/ruby_client/Elements/Element.rb +2 -2
  10. data/lib/ruby_client/Elements/Gs1DataBarBarcodeElement.rb +3 -5
  11. data/lib/ruby_client/Elements/Iata25BarcodeElement.rb +5 -8
  12. data/lib/ruby_client/Elements/MsiBarcodeElement.rb +3 -5
  13. data/lib/ruby_client/Elements/Pdf417BarcodeElement.rb +6 -10
  14. data/lib/ruby_client/Elements/QrCodeElement.rb +2 -4
  15. data/lib/ruby_client/Elements/StackedGs1DataBarBarcodeElement.rb +3 -5
  16. data/lib/ruby_client/Elements/TextBarcodeElement.rb +1 -1
  17. data/lib/ruby_client/FormField.rb +4 -12
  18. data/lib/ruby_client/Imaging/BmpColorFormat.rb +20 -0
  19. data/lib/ruby_client/Imaging/BmpImageFormat.rb +32 -0
  20. data/lib/ruby_client/Imaging/BmpMonochromeColorFormat.rb +37 -0
  21. data/lib/ruby_client/Imaging/ColorFormat.rb +18 -0
  22. data/lib/ruby_client/Imaging/ColorFormatType.rb +31 -0
  23. data/lib/ruby_client/Imaging/CompressionType.rb +16 -0
  24. data/lib/ruby_client/Imaging/DitheringAlgorithm.rb +21 -0
  25. data/lib/ruby_client/Imaging/DpiImageSize.rb +36 -0
  26. data/lib/ruby_client/Imaging/FixedImageSize.rb +39 -0
  27. data/lib/ruby_client/Imaging/GifImageFormat.rb +33 -0
  28. data/lib/ruby_client/Imaging/ImageFormat.rb +31 -0
  29. data/lib/ruby_client/Imaging/ImageFormatType.rb +31 -0
  30. data/lib/ruby_client/Imaging/ImageSize.rb +26 -0
  31. data/lib/ruby_client/Imaging/ImageSizeType.rb +26 -0
  32. data/lib/ruby_client/Imaging/ImageSizeUnit.rb +21 -0
  33. data/lib/ruby_client/Imaging/JpegImageFormat.rb +31 -0
  34. data/lib/ruby_client/Imaging/MaxImageSize.rb +38 -0
  35. data/lib/ruby_client/Imaging/PdfImage.rb +210 -0
  36. data/lib/ruby_client/Imaging/PdfImageResponse.rb +40 -0
  37. data/lib/ruby_client/Imaging/PercentageImageSize.rb +35 -0
  38. data/lib/ruby_client/Imaging/PngColorFormat.rb +18 -0
  39. data/lib/ruby_client/Imaging/PngImageFormat.rb +33 -0
  40. data/lib/ruby_client/Imaging/PngIndexedColorFormat.rb +32 -0
  41. data/lib/ruby_client/Imaging/PngMonochromeColorFormat.rb +23 -0
  42. data/lib/ruby_client/Imaging/QuantizationAlgorithm.rb +26 -0
  43. data/lib/ruby_client/Imaging/TiffColorFormat.rb +17 -0
  44. data/lib/ruby_client/Imaging/TiffImageFormat.rb +34 -0
  45. data/lib/ruby_client/Imaging/TiffIndexedColorFormat.rb +37 -0
  46. data/lib/ruby_client/Imaging/TiffMonochromeColorFormat.rb +40 -0
  47. data/lib/ruby_client/MergeOptions.rb +30 -30
  48. data/lib/ruby_client/Outline.rb +0 -2
  49. data/lib/ruby_client/Pdf.rb +22 -3
  50. data/lib/ruby_client/PdfInput.rb +1 -1
  51. data/lib/ruby_client/PdfInstructions.rb +3 -3
  52. data/lib/ruby_client/version.rb +1 -1
  53. data/lib/ruby_client.rb +29 -0
  54. metadata +31 -2
@@ -0,0 +1,36 @@
1
+ module DynamicPDFApi
2
+ require_relative "ImageSize"
3
+ require_relative "ImageSizeType"
4
+ #
5
+ # Represents an image size defined by DPI (Dots Per Inch).
6
+ #
7
+ class DpiImageSize < ImageSize
8
+ attr_accessor :horizontal_dpi # Gets or sets the horizontal DPI (Dots Per Inch) of the image.
9
+ attr_accessor :vertical_dpi # Gets or sets the vertical DPI (Dots Per Inch) of the image.
10
+
11
+ #
12
+ # Initializes a new instance of the DpiImageSize class and sets the image size type to DPI.
13
+ #
14
+ def initialize
15
+ super
16
+ @horizontal_dpi = nil
17
+ @vertical_dpi = nil
18
+ @type = ImageSizeType::Dpi
19
+ end
20
+
21
+ #
22
+ # Returns a JSON representation of the DpiImageSize object.
23
+ #
24
+ # @return [String] JSON string representing the DpiImageSize object.
25
+ #
26
+ def to_json(_options = {})
27
+ json_array = {}
28
+ json_array['type'] = 'dpi'
29
+
30
+ json_array['horizontalDpi'] = @horizontal_dpi
31
+ json_array['verticalDpi'] = @vertical_dpi
32
+
33
+ JSON.pretty_generate(json_array)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,39 @@
1
+ module DynamicPDFApi
2
+ require_relative "ImageSize"
3
+ require_relative "ImageSizeType"
4
+
5
+
6
+ #
7
+ # Represents an image size with fixed dimensions.
8
+ #
9
+ class FixedImageSize < ImageSize
10
+ attr_accessor :width # Gets or sets the width of the image.
11
+ attr_accessor :height # Gets or sets the height of the image.
12
+ attr_accessor :unit # Gets or sets the unit of measurement ImageSizeUnit for the width and height.
13
+
14
+ #
15
+ # Initializes a new instance of the FixedImageSize class and sets the image size type to Fixed.
16
+ #
17
+ def initialize
18
+ super()
19
+ @type = ImageSizeType::Fixed
20
+ @width = nil
21
+ @height = nil
22
+ @unit = nil
23
+ end
24
+
25
+ #
26
+ # Returns a JSON representation of the FixedImageSize object.
27
+ #
28
+ # @return [String] JSON string representing the FixedImageSize object.
29
+ #
30
+ def to_json(_options = {})
31
+ json_array = {}
32
+ json_array['type'] = 'fixed'
33
+ json_array['width'] = @width
34
+ json_array['height'] = @height
35
+ json_array['unit'] = @unit
36
+ JSON.pretty_generate(json_array)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ module DynamicPDFApi
2
+ require_relative "ImageFormatType"
3
+ require_relative "ImageFormat"
4
+
5
+ # Represents GIF image format with dithering properties.
6
+ #
7
+ class GifImageFormat < ImageFormat
8
+ attr_accessor :dithering_percent # Gets or sets the dithering percentage.
9
+ attr_accessor :dithering_algorithm # Gets or sets the dithering algorithm.
10
+
11
+ #
12
+ # Initializes a new instance of the GifImageFormat class and sets the image format type to GIF.
13
+ #
14
+ def initialize
15
+ super(ImageFormatType::GIF)
16
+ @dithering_percent = nil
17
+ @dithering_algorithm = nil
18
+ end
19
+
20
+ #
21
+ # Returns a JSON representation of the GifImageFormat object.
22
+ #
23
+ # @return [String] JSON string representing the GifImageFormat object.
24
+ #
25
+ def to_json(_options = {})
26
+ json_array = {}
27
+ json_array['ditheringPercent'] = @dithering_percent
28
+ json_array['ditheringAlgorithm'] = @dithering_algorithm
29
+ json_array['type'] = 'gif'
30
+ JSON.pretty_generate(json_array)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ module DynamicPDFApi
2
+ #
3
+ # Base class for image formats.
4
+ #
5
+ class ImageFormat
6
+ #
7
+ # Gets the image format type.
8
+ #
9
+ attr_reader :type
10
+
11
+ #
12
+ # Initializes a new instance of ImageFormat with the specified type.
13
+ #
14
+ # @param type [Symbol] The type of the image format.
15
+ #
16
+ def initialize(type)
17
+ @type = type
18
+ end
19
+
20
+ #
21
+ # Returns a JSON representation of the ImageFormat object.
22
+ #
23
+ # @return [String] JSON string representing the ImageFormat object.
24
+ #
25
+ def to_json(_options = {})
26
+ json_array = {}
27
+ json_array['type'] = @type
28
+ JSON.pretty_generate(json_array)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ module DynamicPDFApi
2
+ #
3
+ # Enum representing supported image formats.
4
+ #
5
+ class ImageFormatType
6
+ #
7
+ # JPEG image format.
8
+ #
9
+ JPEG = :JPEG.freeze
10
+
11
+ #
12
+ # GIF image format.
13
+ #
14
+ GIF = :GIF.freeze
15
+
16
+ #
17
+ # BMP image format.
18
+ #
19
+ BMP = :BMP.freeze
20
+
21
+ #
22
+ # PNG image format.
23
+ #
24
+ PNG = :PNG.freeze
25
+
26
+ #
27
+ # TIFF image format.
28
+ #
29
+ TIFF = :TIFF.freeze
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ module DynamicPDFApi
2
+ #
3
+ # Base class for image size types.
4
+ #
5
+ class ImageSize
6
+ attr_accessor :type # Type of the image size.
7
+
8
+ #
9
+ # Initializes a new instance of the ImageSize class.
10
+ #
11
+ def initialize
12
+ @type = nil
13
+ end
14
+
15
+ #
16
+ # Returns a JSON representation of the ImageSize object.
17
+ #
18
+ # @return [String] JSON string representing the ImageSize object.
19
+ #
20
+ def to_json(_options = {})
21
+ json_array = {}
22
+ json_array['type'] = @type
23
+ JSON.pretty_generate(json_array)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module DynamicPDFApi
2
+ #
3
+ # Enum specifying the type of image size.
4
+ #
5
+ class ImageSizeType
6
+ #
7
+ # DPI-based image size.
8
+ #
9
+ Dpi = :Dpi.freeze
10
+
11
+ #
12
+ # Fixed image size.
13
+ #
14
+ Fixed = :Fixed.freeze
15
+
16
+ #
17
+ # Image size that fits within a given maximum size.
18
+ #
19
+ Max = :Max.freeze
20
+
21
+ #
22
+ # Percentage-based image size.
23
+ #
24
+ Percentage = :Percentage.freeze
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ module DynamicPDFApi
2
+ #
3
+ # Specifies the unit of measurement for image size.
4
+ #
5
+ class ImageSizeUnit
6
+ #
7
+ # Millimeter unit of measurement.
8
+ #
9
+ Millimeter = :Millimeter.freeze
10
+
11
+ #
12
+ # Inch unit of measurement.
13
+ #
14
+ Inch = :Inch.freeze
15
+
16
+ #
17
+ # Point unit of measurement.
18
+ #
19
+ Point = :Point.freeze
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ module DynamicPDFApi
2
+ require_relative "ImageFormat"
3
+ require_relative "ImageFormatType"
4
+
5
+ #
6
+ # Represents JPEG image format with quality.
7
+ #
8
+ class JpegImageFormat < ImageFormat
9
+ attr_accessor :quality # Gets or sets the quality of the JPEG image.
10
+
11
+ #
12
+ # Initializes a new instance of the JpegImageFormat class.
13
+ #
14
+ def initialize
15
+ super(ImageFormatType::JPEG)
16
+ @quality = nil
17
+ end
18
+
19
+ #
20
+ # Returns a JSON representation of the JpegImageFormat object.
21
+ #
22
+ # @return [String] JSON string representing the JpegImageFormat object.
23
+ #
24
+ def to_json(_options = {})
25
+ json_array = {}
26
+ json_array['type'] = 'jpeg'
27
+ json_array['quality'] = @quality
28
+ JSON.pretty_generate(json_array)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ module DynamicPDFApi
2
+ require_relative "ImageSize"
3
+ require_relative "ImageSizeType"
4
+
5
+ #
6
+ # Represents an image size that fits within a specified maximum width and height.
7
+ #
8
+ class MaxImageSize < ImageSize
9
+ attr_accessor :max_width # Gets or sets the maximum width of the image.
10
+ attr_accessor :max_height # Gets or sets the maximum height of the image.
11
+ attr_accessor :unit # Gets or sets the unit of measurement for the maximum width and height.
12
+
13
+ #
14
+ # Initializes a new instance of the MaxImageSize class.
15
+ #
16
+ def initialize
17
+ super()
18
+ @max_width = nil
19
+ @max_height = nil
20
+ @unit = nil
21
+ @type = ImageSizeType::Max
22
+ end
23
+
24
+ #
25
+ # Returns a JSON representation of the MaxImageSize object.
26
+ #
27
+ # @return [String] JSON string representing the MaxImageSize object.
28
+ #
29
+ def to_json(_options = {})
30
+ json_array = {}
31
+ json_array['type'] = 'max'
32
+ json_array['maxWidth'] = @max_width
33
+ json_array['maxHeight'] = @max_height
34
+ json_array['unit'] = @unit
35
+ JSON.pretty_generate(json_array)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,210 @@
1
+ module DynamicPDFApi
2
+
3
+ require "net/http"
4
+ require "net/https"
5
+ require "uri"
6
+ require "json"
7
+ require "openssl"
8
+
9
+ require_relative '..\Endpoint'
10
+ require_relative '..\PdfResource'
11
+ require_relative '..\EndPointException'
12
+ require_relative "PdfImageResponse"
13
+ require_relative "ImageFormat"
14
+ require_relative "ImageSize"
15
+
16
+ # Represents a PDF Rasterizing endpoint that converts PDF to image.
17
+ class PdfImage < Endpoint
18
+
19
+ #
20
+ # Represents a PdfResource for converting PDF pages to images.
21
+ #
22
+ attr_reader :resource
23
+
24
+ #
25
+ # Gets or sets the starting page number for rasterization.
26
+ #
27
+ attr_accessor :start_page_number
28
+
29
+ #
30
+ # Gets or sets the number of pages to rasterize.
31
+ #
32
+ attr_accessor :page_count
33
+
34
+ #
35
+ # Gets or sets the image format for rasterization.
36
+ #
37
+ attr_accessor :image_format
38
+
39
+ #
40
+ # Gets or sets the size of the rasterized images.
41
+ #
42
+ attr_accessor :image_size
43
+
44
+ def initialize(resource)
45
+ @resource = resource
46
+ @_endpoint_name = 'pdf-image'
47
+ end
48
+
49
+ def process
50
+ header = {
51
+ 'authorization': "Bearer #{@api_key}",
52
+ 'Expect': "100-continue",
53
+ }
54
+ uri = URI.parse("#{@base_url}/v1.0/#{@_endpoint_name}")
55
+ params = {}
56
+ if @start_page_number!=nil
57
+ params['sp'] = @start_page_number
58
+ params['pc'] = @page_count
59
+ end
60
+
61
+ # Adding ImageSize parameters if @image_size is present
62
+ if @image_size
63
+ case @image_size
64
+ when DpiImageSize
65
+ params['is'] = @image_size.type.to_s
66
+ params['hd'] = @image_size.horizontal_dpi.to_s if @image_size.horizontal_dpi
67
+ params['vd'] = @image_size.vertical_dpi.to_s if @image_size.vertical_dpi
68
+ when FixedImageSize
69
+ params['is'] = @image_size.type.to_s
70
+ params['ht'] = @image_size.height.to_s if @image_size.height
71
+ params['wd'] = @image_size.width.to_s if @image_size.width
72
+ params['ut'] = @image_size.unit.to_s if @image_size.unit
73
+ when MaxImageSize
74
+ params['is'] = @image_size.type.to_s
75
+ params['mh'] = @image_size.max_height.to_s if @image_size.max_height
76
+ params['mw'] = @image_size.max_width.to_s if @image_size.max_width
77
+ params['ut'] = @image_size.unit.to_s if @image_size.unit
78
+ when PercentageImageSize
79
+ params['is'] = @image_size.type.to_s
80
+ params['hp'] = @image_size.horizontal_percentage.to_s if @image_size.horizontal_percentage
81
+ params['vp'] = @image_size.vertical_percentage.to_s if @image_size.vertical_percentage
82
+ end
83
+ end
84
+
85
+ # Adding ImageFormat parameters if @image_format is present
86
+ if @image_format
87
+ case @image_format
88
+ when GifImageFormat
89
+ params['if'] = @image_format.type.to_s
90
+ params['dp'] = @image_format.dithering_percent.to_s if @image_format.dithering_percent
91
+ params['da'] = @image_format.dithering_algorithm.to_s if @image_format.dithering_algorithm
92
+ when JpegImageFormat
93
+ params['if'] = @image_format.type.to_s
94
+ params['qt'] = @image_format.quality.to_s if @image_format.quality
95
+ when PngImageFormat
96
+ params['if'] = @image_format.type.to_s
97
+ if @image_format.color_format
98
+ params['cf'] = @image_format.color_format.type.to_s
99
+ case @image_format.color_format
100
+ when PngIndexedColorFormat
101
+ params['da'] = @image_format.color_format.dithering_algorithm.to_s if @image_format.color_format.dithering_algorithm
102
+ params['dp'] = @image_format.color_format.dithering_percent.to_s if @image_format.color_format.dithering_percent
103
+ params['qa'] = @image_format.color_format.quantization_algorithm.to_s if @image_format.color_format.quantization_algorithm
104
+ when PngMonochromeColorFormat
105
+ params['bt'] = @image_format.color_format.black_threshold.to_s if @image_format.color_format.black_threshold
106
+ params['da'] = @image_format.color_format.dithering_algorithm.to_s if @image_format.color_format.dithering_algorithm
107
+ params['dp'] = @image_format.color_format.dithering_percent.to_s if @image_format.color_format.dithering_percent
108
+ end
109
+ end
110
+ when TiffImageFormat
111
+ params['if'] = @image_format.type.to_s
112
+ params['mp'] = 'true' if @image_format.multi_page
113
+ if @image_format.color_format
114
+ params['cf'] = @image_format.color_format.type.to_s
115
+ case @image_format.color_format
116
+ when TiffIndexedColorFormat
117
+ params['da'] = @image_format.color_format.dithering_algorithm.to_s if @image_format.color_format.dithering_algorithm
118
+ params['dp'] = @image_format.color_format.dithering_percent.to_s if @image_format.color_format.dithering_percent
119
+ params['qa'] = @image_format.color_format.quantization_algorithm.to_s if @image_format.color_format.quantization_algorithm
120
+ when TiffMonochromeColorFormat
121
+ params['ct'] = @image_format.color_format.compression_type.to_s if @image_format.color_format.compression_type
122
+ params['bt'] = @image_format.color_format.black_threshold.to_s if @image_format.color_format.black_threshold
123
+ params['da'] = @image_format.color_format.dithering_algorithm.to_s if @image_format.color_format.dithering_algorithm
124
+ params['dp'] = @image_format.color_format.dithering_percent.to_s if @image_format.color_format.dithering_percent
125
+ end
126
+ end
127
+ when BmpImageFormat
128
+ params['if'] = @image_format.type.to_s
129
+ if @image_format.color_format
130
+ params['cf'] = @image_format.color_format.type.to_s
131
+ case @image_format.color_format
132
+ when BmpMonochromeColorFormat
133
+ params['bt'] = @image_format.color_format.black_threshold.to_s if @image_format.color_format.black_threshold
134
+ params['dp'] = @image_format.color_format.dithering_percent.to_s if @image_format.color_format.dithering_percent
135
+ params['da'] = @image_format.color_format.dithering_algorithm.to_s if @image_format.color_format.dithering_algorithm
136
+ end
137
+ end
138
+ end
139
+ end
140
+
141
+ uri.query = URI.encode_www_form(params)
142
+
143
+ request = Net::HTTP::Post.new(uri.request_uri, header)
144
+ request.set_form_data(params)
145
+ req_options = {
146
+ use_ssl: uri.scheme == 'https',
147
+ verify_mode: OpenSSL::SSL::VERIFY_NONE
148
+ }
149
+
150
+ resource_array = []
151
+ resource_array << ['pdf', @resource.data, { content_type: @resource._mime_type, filename: @resource.resource_name }] if !@resource.nil?
152
+
153
+ request.set_form(resource_array, "multipart/form-data")
154
+
155
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
156
+ http.request(request)
157
+ end
158
+
159
+ rasterizer_response = PdfImageResponse.new
160
+ if @resource == nil
161
+ raise 'Required a PDF Resource.'
162
+ end
163
+ rasterizer_response.status_code = response.code
164
+ out_data = response.body
165
+ if rasterizer_response.status_code == "200"
166
+ pdf_image = JSON.parse(out_data)
167
+
168
+ image_type = pdf_image['contentType']
169
+ rasterizer_response.image_format = image_type.split('/')[1]
170
+ rasterizer_response.content_type = image_type
171
+ rasterizer_response.horizontal_dpi = pdf_image['horizontalDpi']
172
+ rasterizer_response.vertical_dpi = pdf_image['verticalDpi']
173
+
174
+ pdf_image['images'].each do |img|
175
+ image = Image.new
176
+ image.page_number = img['pageNumber'] || 0
177
+ image.data = img['data'] || ''
178
+ image.billed_pages = img['billedPages'] || 0
179
+ image.width = img['width'] || 0
180
+ image.height = img['height'] || 0
181
+ rasterizer_response.images << image
182
+ end
183
+
184
+ rasterizer_response.status_code = response.code
185
+ rasterizer_response.is_successful = true
186
+ else
187
+ rasterizer_response.error_json = out_data
188
+ rasterizer_response.error_message = if !out_data_json["message"].nil?
189
+ out_data_json["message"]
190
+ else
191
+ "status_code : #{Net::HTTPResponse::CODE_TO_OBJ[rasterizer_response.status_code]}"
192
+ end
193
+ rasterizer_response.error_id = out_data_json["id"]
194
+ rasterizer_response.is_successful = false
195
+ end
196
+
197
+ rasterizer_response
198
+ end
199
+
200
+ def to_json(_options = {})
201
+ json_array = {}
202
+
203
+ json_array["startPageNumber"] = @start_page_number unless @start_page_number.nil?
204
+ json_array["pageCount"] = @page_count unless @page_count.nil?
205
+ json_array["imageFormat"] = @image_format unless @image_format.nil?
206
+ json_array["imageSize"] = @image_size unless @image_size.nil?
207
+ JSON.pretty_generate(json_array)
208
+ end
209
+ end
210
+ end
@@ -0,0 +1,40 @@
1
+ module DynamicPDFApi
2
+ require_relative '..\Response'
3
+
4
+ #
5
+ # Represents a response from the rasterizer operation.
6
+ #
7
+ class PdfImageResponse < Response
8
+
9
+ attr_accessor :image_format
10
+
11
+ attr_accessor :images
12
+
13
+ attr_accessor :content_type
14
+
15
+ attr_accessor :horizontal_dpi
16
+
17
+ attr_accessor :vertical_dpi
18
+
19
+ #
20
+ # Initializes a new instance of the RasterizerResponse class.
21
+ #
22
+ def initialize
23
+ @image_format = nil
24
+ @images = []
25
+ end
26
+ end
27
+
28
+ class Image
29
+ attr_accessor :page_number
30
+
31
+ attr_accessor :data
32
+
33
+ attr_accessor :billed_pages
34
+
35
+ attr_accessor :width
36
+
37
+ attr_accessor :height
38
+
39
+ end
40
+ end
@@ -0,0 +1,35 @@
1
+ module DynamicPDFApi
2
+ require_relative "ImageSize"
3
+ require_relative "ImageSizeType"
4
+
5
+ #
6
+ # Represents an image size based on percentage scaling.
7
+ #
8
+ class PercentageImageSize < ImageSize
9
+ attr_accessor :horizontal_percentage # Gets or sets the horizontal scaling percentage.
10
+ attr_accessor :vertical_percentage # Gets or sets the vertical scaling percentage.
11
+
12
+ #
13
+ # Initializes a new instance of the PercentageImageSize class.
14
+ #
15
+ def initialize
16
+ super()
17
+ @horizontal_percentage = nil
18
+ @vertical_percentage = nil
19
+ @type = ImageSizeType::Percentage
20
+ end
21
+
22
+ #
23
+ # Returns a JSON representation of the PercentageImageSize object.
24
+ #
25
+ # @return [String] JSON string representing the PercentageImageSize object.
26
+ #
27
+ def to_json(_options = {})
28
+ json_array = {}
29
+ json_array['type'] = 'percentage'
30
+ json_array['horizontalPercentage'] = @horizontal_percentage
31
+ json_array['verticalPercentage'] = @vertical_percentage
32
+ JSON.pretty_generate(json_array)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,18 @@
1
+ module DynamicPDFApi
2
+ require_relative 'ColorFormatType'
3
+ require_relative 'ColorFormat'
4
+
5
+ #
6
+ # Base class for PNG color formats, used for RGB, RGBA, and Grayscale color formats.
7
+ #
8
+ class PngColorFormat < ColorFormat
9
+ #
10
+ # Initializes a new instance of the PngColorFormat class.
11
+ #
12
+ # @param type [ColorFormatType] The color format type.
13
+ #
14
+ def initialize(type)
15
+ @type = type
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ module DynamicPDFApi
2
+
3
+ require_relative 'ImageFormatType'
4
+ require_relative 'ImageFormat'
5
+
6
+ #
7
+ # Represents PNG image format with color format.
8
+ #
9
+ class PngImageFormat < ImageFormat
10
+ attr_accessor :color_format # Gets or sets the PngColorFormat for PNG.
11
+
12
+ #
13
+ # Initializes a new instance of the PngImageFormat class.
14
+ #
15
+ def initialize
16
+ super(ImageFormatType::PNG)
17
+ @color_format = nil
18
+ end
19
+
20
+ #
21
+ # Returns a JSON representation of the PngImageFormat object.
22
+ #
23
+ # @return [String] JSON string representing the PngImageFormat object.
24
+ #
25
+ def to_json(_options = {})
26
+ json_array = {}
27
+ json_array['type'] = 'png'
28
+
29
+ json_array['colorFormat'] = @color_format
30
+ JSON.pretty_generate(json_array)
31
+ end
32
+ end
33
+ end