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.
- checksums.yaml +7 -0
- data/lib/ruby_client/Action.rb +15 -0
- data/lib/ruby_client/AdditionalResource.rb +113 -0
- data/lib/ruby_client/AdditionalResourceType.rb +27 -0
- data/lib/ruby_client/Aes128Security.rb +70 -0
- data/lib/ruby_client/Aes256Security.rb +70 -0
- data/lib/ruby_client/Align.rb +21 -0
- data/lib/ruby_client/ButtonFieldInformation.rb +48 -0
- data/lib/ruby_client/ButtonFieldType.rb +16 -0
- data/lib/ruby_client/ChoiceFieldInformation.rb +52 -0
- data/lib/ruby_client/ChoiceFieldType.rb +16 -0
- data/lib/ruby_client/CmykColor.rb +47 -0
- data/lib/ruby_client/Color.rb +12 -0
- data/lib/ruby_client/ColorSpaceType.rb +36 -0
- data/lib/ruby_client/ConverterInput.rb +100 -0
- data/lib/ruby_client/DlexInput.rb +61 -0
- data/lib/ruby_client/DlexLayout.rb +135 -0
- data/lib/ruby_client/DlexResource.rb +40 -0
- data/lib/ruby_client/Elements/AztecBarcodeElement.rb +113 -0
- data/lib/ruby_client/Elements/AztecSymbolSize.rb +206 -0
- data/lib/ruby_client/Elements/BarcodeElement.rb +37 -0
- data/lib/ruby_client/Elements/Code11BarcodeElement.rb +77 -0
- data/lib/ruby_client/Elements/Code128BarcodeElement.rb +105 -0
- data/lib/ruby_client/Elements/Code25BarcodeElement.rb +75 -0
- data/lib/ruby_client/Elements/Code39BarcodeElement.rb +75 -0
- data/lib/ruby_client/Elements/Code93BarcodeElement.rb +75 -0
- data/lib/ruby_client/Elements/Compaction.rb +26 -0
- data/lib/ruby_client/Elements/DataMatrixBarcodeElement.rb +95 -0
- data/lib/ruby_client/Elements/DataMatrixEncodingType.rb +56 -0
- data/lib/ruby_client/Elements/DataMatrixFunctionCharacter.rb +31 -0
- data/lib/ruby_client/Elements/DataMatrixSymbolSize.rb +161 -0
- data/lib/ruby_client/Elements/Dim2BarcodeElement.rb +28 -0
- data/lib/ruby_client/Elements/Element.rb +46 -0
- data/lib/ruby_client/Elements/ElementPlacement.rb +36 -0
- data/lib/ruby_client/Elements/ElementType.rb +96 -0
- data/lib/ruby_client/Elements/ErrorCorrection.rb +56 -0
- data/lib/ruby_client/Elements/Gs1DataBarBarcodeElement.rb +76 -0
- data/lib/ruby_client/Elements/Gs1DataBarType.rb +22 -0
- data/lib/ruby_client/Elements/Iata25BarcodeElement.rb +83 -0
- data/lib/ruby_client/Elements/ImageElement.rb +108 -0
- data/lib/ruby_client/Elements/LineElement.rb +92 -0
- data/lib/ruby_client/Elements/MsiBarcodeCheckDigitMode.rb +31 -0
- data/lib/ruby_client/Elements/MsiBarcodeElement.rb +79 -0
- data/lib/ruby_client/Elements/PageNumberingElement.rb +91 -0
- data/lib/ruby_client/Elements/Pdf417BarcodeElement.rb +112 -0
- data/lib/ruby_client/Elements/QrCodeElement.rb +77 -0
- data/lib/ruby_client/Elements/QrCodeFnc1.rb +22 -0
- data/lib/ruby_client/Elements/RectangleElement.rb +109 -0
- data/lib/ruby_client/Elements/StackedGs1DataBarBarcodeElement.rb +90 -0
- data/lib/ruby_client/Elements/StackedGs1DataBarType.rb +23 -0
- data/lib/ruby_client/Elements/TextBarcodeElement.rb +48 -0
- data/lib/ruby_client/Elements/TextElement.rb +83 -0
- data/lib/ruby_client/Elements/ValueType.rb +16 -0
- data/lib/ruby_client/EncryptDocumentComponents.rb +16 -0
- data/lib/ruby_client/EndPointException.rb +7 -0
- data/lib/ruby_client/Endpoint.rb +38 -0
- data/lib/ruby_client/EndpointResource.rb +7 -0
- data/lib/ruby_client/ExcelInput.rb +49 -0
- data/lib/ruby_client/ExcelResource.rb +79 -0
- data/lib/ruby_client/Font.rb +276 -0
- data/lib/ruby_client/FontInformation.rb +9 -0
- data/lib/ruby_client/FontResource.rb +35 -0
- data/lib/ruby_client/FormField.rb +62 -0
- data/lib/ruby_client/FormFieldInformation.rb +45 -0
- data/lib/ruby_client/GoToAction.rb +53 -0
- data/lib/ruby_client/Grayscale.rb +41 -0
- data/lib/ruby_client/HtmlInput.rb +60 -0
- data/lib/ruby_client/HtmlResource.rb +34 -0
- data/lib/ruby_client/ImageInfo.rb +69 -0
- data/lib/ruby_client/ImageInformation.rb +57 -0
- data/lib/ruby_client/ImageInput.rb +150 -0
- data/lib/ruby_client/ImageResource.rb +89 -0
- data/lib/ruby_client/ImageResponse.rb +24 -0
- data/lib/ruby_client/Input.rb +53 -0
- data/lib/ruby_client/InputType.rb +41 -0
- data/lib/ruby_client/JsonResponse.rb +18 -0
- data/lib/ruby_client/LayoutDataResource.rb +48 -0
- data/lib/ruby_client/LineStyle.rb +79 -0
- data/lib/ruby_client/MergeOptions.rb +135 -0
- data/lib/ruby_client/MultiSelectListBoxInformation.rb +45 -0
- data/lib/ruby_client/Outline.rb +113 -0
- data/lib/ruby_client/OutlineList.rb +57 -0
- data/lib/ruby_client/OutlineStyle.rb +28 -0
- data/lib/ruby_client/OutputSize.rb +10 -0
- data/lib/ruby_client/PageInformation.rb +27 -0
- data/lib/ruby_client/PageInput.rb +152 -0
- data/lib/ruby_client/PageOrientation.rb +17 -0
- data/lib/ruby_client/PageSize.rb +127 -0
- data/lib/ruby_client/PageZoom.rb +33 -0
- data/lib/ruby_client/Pdf.rb +417 -0
- data/lib/ruby_client/PdfContent.rb +21 -0
- data/lib/ruby_client/PdfInfo.rb +68 -0
- data/lib/ruby_client/PdfInfoResponse.rb +27 -0
- data/lib/ruby_client/PdfInformation.rb +81 -0
- data/lib/ruby_client/PdfInput.rb +66 -0
- data/lib/ruby_client/PdfInstructions.rb +97 -0
- data/lib/ruby_client/PdfResource.rb +36 -0
- data/lib/ruby_client/PdfResponse.rb +23 -0
- data/lib/ruby_client/PdfText.rb +85 -0
- data/lib/ruby_client/PdfTextResponse.rb +27 -0
- data/lib/ruby_client/PdfXmp.rb +67 -0
- data/lib/ruby_client/PushButtonInformation.rb +21 -0
- data/lib/ruby_client/RC4128Security.rb +62 -0
- data/lib/ruby_client/Resource.rb +51 -0
- data/lib/ruby_client/ResourceType.rb +48 -0
- data/lib/ruby_client/Response.rb +39 -0
- data/lib/ruby_client/RgbColor.rb +1048 -0
- data/lib/ruby_client/Security.rb +73 -0
- data/lib/ruby_client/SecurityType.rb +23 -0
- data/lib/ruby_client/SignatureFieldInformation.rb +21 -0
- data/lib/ruby_client/Template.rb +46 -0
- data/lib/ruby_client/TextFieldInformation.rb +27 -0
- data/lib/ruby_client/TextReplace.rb +43 -0
- data/lib/ruby_client/UnitConverter.rb +111 -0
- data/lib/ruby_client/UrlAction.rb +31 -0
- data/lib/ruby_client/VAlign.rb +21 -0
- data/lib/ruby_client/WebColor.rb +18 -0
- data/lib/ruby_client/WordInput.rb +65 -0
- data/lib/ruby_client/WordResource.rb +82 -0
- data/lib/ruby_client/XmlResponse.rb +23 -0
- data/lib/ruby_client/version.rb +5 -0
- data/lib/ruby_client.rb +123 -0
- metadata +169 -0
@@ -0,0 +1,417 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require "net/http"
|
3
|
+
require "net/https"
|
4
|
+
require "uri"
|
5
|
+
require "json"
|
6
|
+
require "openssl"
|
7
|
+
|
8
|
+
require_relative "Endpoint"
|
9
|
+
require_relative "PdfInstructions"
|
10
|
+
require_relative "Input"
|
11
|
+
require_relative "PdfInput"
|
12
|
+
require_relative "Resource"
|
13
|
+
require_relative "PdfResource"
|
14
|
+
require_relative "PdfResponse"
|
15
|
+
require_relative "PageInput"
|
16
|
+
require_relative "OutlineList"
|
17
|
+
|
18
|
+
#
|
19
|
+
# Represents a pdf endpoint.
|
20
|
+
#
|
21
|
+
class Pdf < Endpoint
|
22
|
+
#
|
23
|
+
# Initializes a new instance of the Pdf class.
|
24
|
+
#
|
25
|
+
def initialize
|
26
|
+
super
|
27
|
+
@_endpoint_name = "pdf"
|
28
|
+
@out_lines = OutlineList.new
|
29
|
+
@instructions = PdfInstructions.new
|
30
|
+
@author = nil
|
31
|
+
@resources = {}
|
32
|
+
@title = nil
|
33
|
+
@subject = nil
|
34
|
+
@creator = ""
|
35
|
+
@producer = ""
|
36
|
+
@tag = nil
|
37
|
+
@keywords = nil
|
38
|
+
@security = nil
|
39
|
+
@flatten_all_form_fields = nil
|
40
|
+
@retain_signature_form_fields = nil
|
41
|
+
@inputs = []
|
42
|
+
@templates = {}
|
43
|
+
@fonts = {}
|
44
|
+
@form_fields = []
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Adds additional resource to the endpoint.
|
49
|
+
#
|
50
|
+
# <param name="resourcePath">The resource file path.
|
51
|
+
# <param name="resourceName">The name of the resource.
|
52
|
+
def add_additional_resource(resourcePath, resourceName = nil)
|
53
|
+
if (resourceName == nil)
|
54
|
+
resourceName = Path.GetFileName(resourcePath)
|
55
|
+
end
|
56
|
+
|
57
|
+
resource = AdditionalResource.new(resourcePath, resourceName)
|
58
|
+
@resources.Add(resource)
|
59
|
+
end
|
60
|
+
|
61
|
+
attr_accessor :instructions
|
62
|
+
|
63
|
+
#
|
64
|
+
# Gets or sets the collection of resource.
|
65
|
+
#
|
66
|
+
attr_accessor :resources
|
67
|
+
|
68
|
+
#
|
69
|
+
# Gets or sets the author.
|
70
|
+
#
|
71
|
+
attr_accessor :author
|
72
|
+
|
73
|
+
#
|
74
|
+
# Gets or sets the title.
|
75
|
+
#
|
76
|
+
attr_accessor :title
|
77
|
+
|
78
|
+
#
|
79
|
+
# Gets or sets the subject.
|
80
|
+
#
|
81
|
+
attr_accessor :subject
|
82
|
+
|
83
|
+
#
|
84
|
+
# Gets or sets the creator.
|
85
|
+
#
|
86
|
+
attr_accessor :creator
|
87
|
+
|
88
|
+
#
|
89
|
+
# Gets or sets the PDF producer.
|
90
|
+
#
|
91
|
+
attr_accessor :producer
|
92
|
+
|
93
|
+
#
|
94
|
+
# Gets or sets the Tag property.
|
95
|
+
#
|
96
|
+
attr_accessor :tag
|
97
|
+
|
98
|
+
#
|
99
|
+
# Gets or sets the keywords.
|
100
|
+
#
|
101
|
+
attr_accessor :keywords
|
102
|
+
|
103
|
+
#
|
104
|
+
# Gets or sets the security.
|
105
|
+
#
|
106
|
+
attr_accessor :security
|
107
|
+
|
108
|
+
#
|
109
|
+
# Gets or sets the value indicating whether to flatten all form fields.
|
110
|
+
#
|
111
|
+
attr_accessor :flatten_all_form_fields
|
112
|
+
|
113
|
+
#
|
114
|
+
# Gets or sets the value indicating whether to retain signature form field.
|
115
|
+
#
|
116
|
+
attr_accessor :retain_signature_form_fields
|
117
|
+
|
118
|
+
#
|
119
|
+
# Returns a PdfInput object containing the input pdf.
|
120
|
+
#
|
121
|
+
# @param resource [String]|[PdfResource] The resource path in cloud resource manager or the resource of type PdfResource.
|
122
|
+
# @param options [MergeOptions] The merge options for the pdf.
|
123
|
+
#
|
124
|
+
# @return PdfInput PdfInput object.
|
125
|
+
#
|
126
|
+
def add_pdf(resource, options = nil)
|
127
|
+
input = PdfInput.new(resource, options)
|
128
|
+
@inputs << input
|
129
|
+
input
|
130
|
+
end
|
131
|
+
|
132
|
+
#
|
133
|
+
# Returns an ImageInput object containing the input pdf.
|
134
|
+
#
|
135
|
+
# @param resource [String]|[ImageResource] The resource path in cloud resource manager or the resource of type ImageResource.
|
136
|
+
#
|
137
|
+
# @return ImageInput ImageInput object.
|
138
|
+
#
|
139
|
+
def add_image(resource)
|
140
|
+
input = ImageInput.new(resource)
|
141
|
+
@inputs << input
|
142
|
+
input
|
143
|
+
end
|
144
|
+
|
145
|
+
#
|
146
|
+
# Returns an HtmlInput object containing the input pdf.
|
147
|
+
#
|
148
|
+
# @param resource [String]|[HtmlResource] The resource of type HtmlResource.
|
149
|
+
#
|
150
|
+
# @return HtmlInput HtmlInput object.
|
151
|
+
#
|
152
|
+
def add_html(html, basepath = null, size = PageSize.A4, orientation = PageOrientation.PORTRAIT, margins = nil)
|
153
|
+
input = nil
|
154
|
+
if file.is_a?(String)
|
155
|
+
input = HtmlInput.new(HtmlResource.new(html), basepath, size, orientation, margins)
|
156
|
+
else
|
157
|
+
input = HtmlInput.new(resource, basepath, size, orientation, margins)
|
158
|
+
end
|
159
|
+
|
160
|
+
@inputs << input
|
161
|
+
input
|
162
|
+
end
|
163
|
+
|
164
|
+
#
|
165
|
+
# Returns a WordInput object containing the input pdf.
|
166
|
+
#
|
167
|
+
# @param resource [WordResource] The resource of type WordResource.
|
168
|
+
#
|
169
|
+
# @return WordInput WordInput object.
|
170
|
+
#
|
171
|
+
def add_word(resource, size = PageSize.A4, orientation = PageOrientation.PORTRAIT, margins = nil)
|
172
|
+
input = WordInput.new(resource, size, orientation, margins)
|
173
|
+
@inputs << input
|
174
|
+
input
|
175
|
+
end
|
176
|
+
|
177
|
+
#
|
178
|
+
# Returns a ExcelInput object containing the input pdf.
|
179
|
+
#
|
180
|
+
# @param resource [ExcelResource] The resource of type ExcelResource.
|
181
|
+
#
|
182
|
+
# @return ExcelInput ExcelInput object.
|
183
|
+
#
|
184
|
+
def add_excel(resource, size = PageSize.A4, orientation = PageOrientation.PORTRAIT, margins = nil)
|
185
|
+
input = ExcelInput.new(resource, size, orientation, margins)
|
186
|
+
@inputs << input
|
187
|
+
input
|
188
|
+
end
|
189
|
+
|
190
|
+
#
|
191
|
+
# Returns a DlexInput object containing the input pdf.
|
192
|
+
#
|
193
|
+
# @param dlex [String]|[DlexResource] The resource path in cloud resource manager or the dlex resource of type DlexResource.
|
194
|
+
# @param layout_data [String]|[Layout_dataResource] The layout data resource path in cloud resource manager or the layout data resource of type Layout_dataResource.
|
195
|
+
#
|
196
|
+
# @return DlexInput DlexInput object.
|
197
|
+
#
|
198
|
+
def add_dlex(dlex, layout)
|
199
|
+
input = DlexInput.new(dlex, layout)
|
200
|
+
@inputs << input
|
201
|
+
input
|
202
|
+
end
|
203
|
+
|
204
|
+
#
|
205
|
+
# Returns a page_input object containing the input pdf.
|
206
|
+
#
|
207
|
+
# @param page_width [float] The width of the page.
|
208
|
+
# @param page_height [float] The height of the page.
|
209
|
+
#
|
210
|
+
# @return page_input page_input object.
|
211
|
+
#
|
212
|
+
def add_page(page_width = nil, page_height = nil)
|
213
|
+
input = if !page_width.nil? && !page_height.nil?
|
214
|
+
PageInput.new(page_width, page_height)
|
215
|
+
else
|
216
|
+
PageInput.new
|
217
|
+
end
|
218
|
+
@inputs << input
|
219
|
+
input
|
220
|
+
end
|
221
|
+
|
222
|
+
#
|
223
|
+
# Gets the inputs.
|
224
|
+
#
|
225
|
+
attr_reader :inputs
|
226
|
+
|
227
|
+
def inputs=(_value)
|
228
|
+
@inputs = {}
|
229
|
+
end
|
230
|
+
|
231
|
+
#
|
232
|
+
# Gets the templates.
|
233
|
+
#
|
234
|
+
attr_accessor :templates
|
235
|
+
|
236
|
+
#
|
237
|
+
# Gets the fonts.
|
238
|
+
#
|
239
|
+
attr_accessor :fonts
|
240
|
+
|
241
|
+
#
|
242
|
+
# Gets the formFields.
|
243
|
+
#
|
244
|
+
attr_accessor :form_fields
|
245
|
+
|
246
|
+
#
|
247
|
+
# Gets the outlines.
|
248
|
+
#
|
249
|
+
attr_accessor :out_lines
|
250
|
+
|
251
|
+
#
|
252
|
+
# Process to create pdf.
|
253
|
+
#
|
254
|
+
# @return PdfResponse Returns collection of PdfResponse.
|
255
|
+
#
|
256
|
+
def process
|
257
|
+
@instructions._author = @author
|
258
|
+
@instructions._title = @title
|
259
|
+
@instructions._subject = @subject
|
260
|
+
@instructions._creator = @creator
|
261
|
+
@instructions._producer = @producer
|
262
|
+
@instructions._tag = @tag
|
263
|
+
@instructions._keywords = @keywords
|
264
|
+
@instructions._security = @security
|
265
|
+
@instructions._flatten_all_form_fields = @flatten_all_form_fields
|
266
|
+
@instructions._retain_signature_form_fields = @retain_signature_form_fields
|
267
|
+
@instructions._inputs = @inputs
|
268
|
+
|
269
|
+
@instructions._templates = @templates
|
270
|
+
@instructions._fonts = @fonts
|
271
|
+
@instructions._form_fields = @form_fields
|
272
|
+
@instructions._out_lines = @out_lines
|
273
|
+
# @Instructions.form_fields = @form_fields
|
274
|
+
|
275
|
+
@instructions._inputs.each do |input|
|
276
|
+
if input._type == InputType::PAGE
|
277
|
+
page_input = input
|
278
|
+
page_input.elements.each do |element|
|
279
|
+
@resources[element._resource.resource_name] = element._resource unless element._resource.nil?
|
280
|
+
if !element._text_font.nil?
|
281
|
+
font_serialized_array = element._text_font
|
282
|
+
@instructions._fonts[element._text_font._name] = font_serialized_array
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
input._resources.each do |resource|
|
288
|
+
@resources[resource.resource_name] = resource unless resource.nil?
|
289
|
+
end
|
290
|
+
|
291
|
+
if !input.get_template.nil?
|
292
|
+
template = input.get_template
|
293
|
+
@instructions._templates[template.id] = template
|
294
|
+
if !input.get_template.elements.nil? && !input.get_template.elements.empty?
|
295
|
+
input.get_template.elements.each do |element|
|
296
|
+
@resources[element._resource.resource_name] = element._resource unless element._resource.nil?
|
297
|
+
if !element._text_font.nil?
|
298
|
+
font_serialized_array = element._text_font
|
299
|
+
|
300
|
+
@instructions._fonts[element._text_font._name] = font_serialized_array
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
data_string = @instructions.to_json
|
308
|
+
|
309
|
+
header = {
|
310
|
+
'authorization': "Bearer #{@api_key}",
|
311
|
+
'Expect': "100-continue",
|
312
|
+
}
|
313
|
+
uri = URI.parse("#{@base_url}/v1.0/#{@_endpoint_name}")
|
314
|
+
request = Net::HTTP::Post.new(uri.request_uri, header)
|
315
|
+
|
316
|
+
req_options = {
|
317
|
+
use_ssl: uri.scheme == "https",
|
318
|
+
verify_mode: OpenSSL::SSL::VERIFY_NONE,
|
319
|
+
|
320
|
+
}
|
321
|
+
|
322
|
+
resource_array = []
|
323
|
+
resource_array << ["Instructions", data_string,
|
324
|
+
{ content_type: "application/octet-stream", filename: "Instructions.json" }]
|
325
|
+
@resources.each_value do |field|
|
326
|
+
data = if !field._file_path.nil?
|
327
|
+
File.binread(field._file_path)
|
328
|
+
else
|
329
|
+
field.data
|
330
|
+
end
|
331
|
+
|
332
|
+
resource_array << ["Resource", data,
|
333
|
+
{ content_type: "application/octet-stream", filename: field.resource_name }]
|
334
|
+
end
|
335
|
+
request.set_form(resource_array, "multipart/form-data")
|
336
|
+
|
337
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
338
|
+
http.request(request)
|
339
|
+
end
|
340
|
+
|
341
|
+
ret_object = PdfResponse.new
|
342
|
+
ret_object.is_successful = false
|
343
|
+
ret_object.status_code = response.code
|
344
|
+
out_data = response.body
|
345
|
+
|
346
|
+
if !ret_object.nil? && ret_object.status_code == "200" && out_data[0, 4].eql?("%PDF") == true
|
347
|
+
ret_object = PdfResponse.new(out_data)
|
348
|
+
ret_object.is_successful = true
|
349
|
+
else
|
350
|
+
out_data_json = JSON.parse(out_data)
|
351
|
+
ret_object.error_json = out_data
|
352
|
+
ret_object.error_message = if !out_data_json["message"].nil?
|
353
|
+
out_data_json["message"]
|
354
|
+
else
|
355
|
+
"status_code : #{Net::HTTPResponse::CODE_TO_OBJ[ret_object.status_code]}"
|
356
|
+
end
|
357
|
+
ret_object.error_id = out_data_json["id"]
|
358
|
+
end
|
359
|
+
|
360
|
+
ret_object
|
361
|
+
end
|
362
|
+
|
363
|
+
def get_instructions_json(indented = false)
|
364
|
+
@tembInstructions = PdfInstructions.new
|
365
|
+
@tembInstructions._author = @author
|
366
|
+
@tembInstructions._title = @title
|
367
|
+
@tembInstructions._subject = @subject
|
368
|
+
@tembInstructions._creator = @creator
|
369
|
+
@tembInstructions._producer = @producer
|
370
|
+
@tembInstructions._tag = @tag
|
371
|
+
@tembInstructions._keywords = @keywords
|
372
|
+
@tembInstructions._security = @security
|
373
|
+
@tembInstructions._flatten_all_form_fields = @flatten_all_form_fields
|
374
|
+
@tembInstructions._retain_signature_form_fields = @retain_signature_form_fields
|
375
|
+
@tembInstructions._inputs = @inputs
|
376
|
+
@tembInstructions._templates = @templates
|
377
|
+
@tembInstructions._fonts = @fonts
|
378
|
+
@tembInstructions._form_fields = @form_fields
|
379
|
+
@tembInstructions._out_lines = @out_lines
|
380
|
+
# @tembInstructions.form_fields = @form_fields
|
381
|
+
|
382
|
+
@tembInstructions._inputs.each do |input|
|
383
|
+
if input._type == InputType::PAGE
|
384
|
+
page_input = input
|
385
|
+
page_input.elements.each do |element|
|
386
|
+
@resources[element._resource.resource_name] = element._resource unless element._resource.nil?
|
387
|
+
if !element._text_font.nil?
|
388
|
+
font_serialized_array = element._text_font
|
389
|
+
@tembInstructions._fonts[element._text_font._name] = font_serialized_array
|
390
|
+
end
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
input._resources.each do |resource|
|
395
|
+
@resources[resource.resource_name] = resource unless resource.nil?
|
396
|
+
end
|
397
|
+
|
398
|
+
if !input.get_template.nil?
|
399
|
+
template = input.get_template
|
400
|
+
@tembInstructions._templates[template.id] = template
|
401
|
+
if !input.get_template.elements.nil? && !input.get_template.elements.empty?
|
402
|
+
input.get_template.elements.each do |element|
|
403
|
+
@resources[element._resource.resource_name] = element._resource unless element._resource.nil?
|
404
|
+
if !element._text_font.nil?
|
405
|
+
font_serialized_array = element._text_font
|
406
|
+
|
407
|
+
@tembInstructions._fonts[element._text_font._name] = font_serialized_array
|
408
|
+
end
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
end
|
413
|
+
#data_string = @instructions.to_json
|
414
|
+
@tembInstructions.to_json
|
415
|
+
end
|
416
|
+
end
|
417
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
#
|
3
|
+
# Represents the pdf content
|
4
|
+
#
|
5
|
+
class PdfContent
|
6
|
+
def initialize
|
7
|
+
@page_number = nil
|
8
|
+
@text = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
#
|
12
|
+
# Gets or sets the page number.
|
13
|
+
#
|
14
|
+
attr_accessor :page_number
|
15
|
+
|
16
|
+
#
|
17
|
+
# Gets the text in the pdf.
|
18
|
+
#
|
19
|
+
attr_accessor :text
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require_relative 'Endpoint'
|
3
|
+
require_relative 'PdfInfoResponse'
|
4
|
+
|
5
|
+
#
|
6
|
+
# Represents the pdf info endpoint.
|
7
|
+
#
|
8
|
+
class PdfInfo < Endpoint
|
9
|
+
#
|
10
|
+
# Initializes a new instance of the PdfInfo class.
|
11
|
+
#
|
12
|
+
# @param resource [PdfResource] The resource of type PdfResource.
|
13
|
+
#
|
14
|
+
def initialize(resource)
|
15
|
+
super()
|
16
|
+
@resource = resource
|
17
|
+
@_endpoint_name = 'pdf-info'
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# Process the pdf resource to get pdf's information.
|
22
|
+
# @return PdfInfoResponse Returns collection of PdfInfoResponse.
|
23
|
+
#
|
24
|
+
def process
|
25
|
+
header = {
|
26
|
+
'Authorization': "Bearer #{@api_key}",
|
27
|
+
'Content-Length': @resource.data.length.to_s,
|
28
|
+
'Expect': '100-continue',
|
29
|
+
'Content-Type': 'application/pdf'
|
30
|
+
}
|
31
|
+
uri = URI.parse("#{@base_url}/v1.0/#{@_endpoint_name}")
|
32
|
+
|
33
|
+
request = Net::HTTP::Post.new(uri.request_uri, header)
|
34
|
+
|
35
|
+
req_options = {
|
36
|
+
use_ssl: uri.scheme == 'https',
|
37
|
+
verify_mode: OpenSSL::SSL::VERIFY_NONE
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
request.content_type = 'application/pdf'
|
42
|
+
|
43
|
+
request.body = @resource.data
|
44
|
+
|
45
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
46
|
+
http.request(request)
|
47
|
+
end
|
48
|
+
out_data = response.body
|
49
|
+
ret_object = PdfInfoResponse.new(out_data)
|
50
|
+
ret_object.is_successful = false
|
51
|
+
ret_object.status_code = response.code
|
52
|
+
if ret_object.status_code == '200'
|
53
|
+
ret_object.is_successful = true
|
54
|
+
else
|
55
|
+
out_data_json = JSON.parse(out_data)
|
56
|
+
ret_object.error_json = out_data
|
57
|
+
ret_object.error_message = if !out_data_json['message'].nil?
|
58
|
+
out_data_json['message']
|
59
|
+
else
|
60
|
+
"status_code : #{Net::HTTPResponse::CODE_TO_OBJ[ret_object.status_code]}"
|
61
|
+
end
|
62
|
+
ret_object.error_id = out_data_json['id']
|
63
|
+
end
|
64
|
+
|
65
|
+
ret_object
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require_relative 'JsonResponse'
|
3
|
+
|
4
|
+
#
|
5
|
+
# Represents the pdf information response.
|
6
|
+
#
|
7
|
+
class PdfInfoResponse < JsonResponse
|
8
|
+
#
|
9
|
+
# Initializes a new instance of the PdfInfoResponse class.
|
10
|
+
#
|
11
|
+
# @param json_content [String] The json of pdf information.
|
12
|
+
#
|
13
|
+
def initialize(json_content = nil)
|
14
|
+
@content = []
|
15
|
+
return if json_content.nil?
|
16
|
+
|
17
|
+
super(json_content)
|
18
|
+
@content = JSON.pretty_generate(json_content).gsub('\\\\', '\\').gsub('\"', '"').gsub('\\\r', '\r').gsub('\\\n', '\n').gsub('\\\t', '\t')
|
19
|
+
@content = @content[1..@content.length - 2]
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Gets the pdf information content.
|
24
|
+
#
|
25
|
+
attr_accessor :content
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
#
|
3
|
+
# Represents the pdf information.
|
4
|
+
#
|
5
|
+
class PdfInformation
|
6
|
+
def initialize
|
7
|
+
@author = nil
|
8
|
+
@subject = nil
|
9
|
+
@keywords = nil
|
10
|
+
@creator = nil
|
11
|
+
@producer = nil
|
12
|
+
@title = nil
|
13
|
+
@pages = {}
|
14
|
+
@form_fields = nil
|
15
|
+
@custom_properties = nil
|
16
|
+
@xmp_meta_data = nil
|
17
|
+
@signed = nil
|
18
|
+
@tagged = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Gets the author.
|
23
|
+
#
|
24
|
+
attr_accessor :author
|
25
|
+
|
26
|
+
#
|
27
|
+
# Gets the subject.
|
28
|
+
#
|
29
|
+
attr_accessor :subject
|
30
|
+
|
31
|
+
#
|
32
|
+
# Gets the keywords.
|
33
|
+
#
|
34
|
+
attr_accessor :keywords
|
35
|
+
|
36
|
+
#
|
37
|
+
# Gets the creator.
|
38
|
+
#
|
39
|
+
attr_accessor :creator
|
40
|
+
|
41
|
+
#
|
42
|
+
# Gets the producer.
|
43
|
+
#
|
44
|
+
attr_accessor :producer
|
45
|
+
|
46
|
+
#
|
47
|
+
# Gets the title.
|
48
|
+
#
|
49
|
+
attr_accessor :title
|
50
|
+
|
51
|
+
#
|
52
|
+
# Gets the collection of PageInformation.
|
53
|
+
#
|
54
|
+
attr_accessor :pages
|
55
|
+
|
56
|
+
#
|
57
|
+
# Gets the form fields.
|
58
|
+
#
|
59
|
+
attr_accessor :form_fields
|
60
|
+
|
61
|
+
#
|
62
|
+
# Gets the custom properties.
|
63
|
+
#
|
64
|
+
attr_accessor :custom_properties
|
65
|
+
|
66
|
+
#
|
67
|
+
# Gets the boolean representing xmp meta data.
|
68
|
+
#
|
69
|
+
attr_accessor :xmp_meta_data
|
70
|
+
|
71
|
+
#
|
72
|
+
# Gets the boolean, indicating whether the pdf is signed.
|
73
|
+
#
|
74
|
+
attr_accessor :signed
|
75
|
+
|
76
|
+
#
|
77
|
+
# Gets the boolean, indicating whether the pdf is tagged.
|
78
|
+
#
|
79
|
+
attr_accessor :tagged
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require_relative 'Input'
|
3
|
+
require_relative 'InputType'
|
4
|
+
require_relative 'MergeOptions'
|
5
|
+
require_relative 'PdfResource'
|
6
|
+
|
7
|
+
#
|
8
|
+
# Represents a pdf input.
|
9
|
+
#
|
10
|
+
class PdfInput < Input
|
11
|
+
#
|
12
|
+
# Initializes a new instance of the PdfInput class.
|
13
|
+
#
|
14
|
+
# @param resource [String]|[PdfResource] The resource path in cloud resource manager or the resource of type PdfResource.
|
15
|
+
# @param options [MergeOptions] The merge options for the pdf.
|
16
|
+
#
|
17
|
+
def initialize(resource, options = nil)
|
18
|
+
@id = nil
|
19
|
+
@_type = InputType::PDF
|
20
|
+
@start_page = nil
|
21
|
+
@page_count = nil
|
22
|
+
@merge_options = options
|
23
|
+
super(resource)
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_accessor :_type
|
27
|
+
|
28
|
+
#
|
29
|
+
# Gets or sets the merge options MergeOptions.
|
30
|
+
#
|
31
|
+
attr_accessor :merge_options
|
32
|
+
|
33
|
+
#
|
34
|
+
# Gets or sets the start page.
|
35
|
+
#
|
36
|
+
attr_accessor :start_page
|
37
|
+
|
38
|
+
#
|
39
|
+
# Gets or sets the page count.
|
40
|
+
#
|
41
|
+
attr_accessor :page_count
|
42
|
+
|
43
|
+
def to_json(_options = {})
|
44
|
+
@template = get_template
|
45
|
+
json_array = {}
|
46
|
+
|
47
|
+
json_array['type'] = 'pdf'
|
48
|
+
|
49
|
+
json_array['mergeOptions'] = @merge_options unless @merge_options.nil?
|
50
|
+
|
51
|
+
json_array['startPage'] = @start_page unless @start_page.nil?
|
52
|
+
|
53
|
+
json_array['pageCount'] = @page_count unless @page_count.nil?
|
54
|
+
|
55
|
+
#---------------------------------------------------
|
56
|
+
|
57
|
+
json_array['templateId'] = @_template_id
|
58
|
+
|
59
|
+
json_array['resourceName'] = @resource_name
|
60
|
+
|
61
|
+
json_array['id'] = @id
|
62
|
+
|
63
|
+
JSON.pretty_generate(json_array)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|