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,97 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require_relative 'Security'
|
3
|
+
require_relative 'FormField'
|
4
|
+
require_relative 'Font'
|
5
|
+
|
6
|
+
class PdfInstructions
|
7
|
+
attr_accessor :_form_fields, :_templates, :_fonts, :_out_lines, :_inputs, :_author, :_title, :_subject, :_creator, :_producer, :_tag,
|
8
|
+
:_keywords, :_security, :_flatten_all_form_fields, :_retain_signature_form_fields
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@_author = ''
|
12
|
+
@_title = ''
|
13
|
+
@_subject = ''
|
14
|
+
@_creator = ''
|
15
|
+
@_producer = ''
|
16
|
+
@_tag = nil
|
17
|
+
@_keywords = ''
|
18
|
+
@_form_fields = []
|
19
|
+
@_templates = {}
|
20
|
+
@_fonts = {}
|
21
|
+
@_outlines = []
|
22
|
+
@_inputs = []
|
23
|
+
@_security = nil
|
24
|
+
@_flatten_all_form_fields = nil
|
25
|
+
@_retain_signature_form_fields = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_json( indented = false)
|
29
|
+
# @inputJsonArray = []
|
30
|
+
|
31
|
+
# @_Inputs.each do |input|
|
32
|
+
# if(input != nil)
|
33
|
+
# @inputJsonArray << input
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
|
37
|
+
fonts_json = []
|
38
|
+
@_fonts.each_value do |font|
|
39
|
+
fonts_json << font
|
40
|
+
end
|
41
|
+
|
42
|
+
templates_json = []
|
43
|
+
@_templates.each_value do |template|
|
44
|
+
templates_json << template unless template.nil?
|
45
|
+
end
|
46
|
+
|
47
|
+
json_array = {}
|
48
|
+
|
49
|
+
if(templates_json.length > 0)
|
50
|
+
json_array['templates'] = templates_json
|
51
|
+
end
|
52
|
+
|
53
|
+
if(fonts_json.length > 0)
|
54
|
+
json_array['fonts'] = fonts_json
|
55
|
+
end
|
56
|
+
|
57
|
+
if(@_author != nil)
|
58
|
+
json_array['author'] = @_author
|
59
|
+
end
|
60
|
+
|
61
|
+
if(@_title != nil)
|
62
|
+
json_array['title'] = @_title
|
63
|
+
end
|
64
|
+
|
65
|
+
json_array['subject'] = @_subject unless @_subject.nil?
|
66
|
+
|
67
|
+
json_array['creator'] = @_creator unless @_creator.nil?
|
68
|
+
|
69
|
+
json_array['producer'] = @_producer unless @_producer.nil?
|
70
|
+
|
71
|
+
json_array['tag'] = @_tag unless @_tag.nil?
|
72
|
+
|
73
|
+
json_array['keywords'] = @_keywords unless @_keywords.nil?
|
74
|
+
|
75
|
+
json_array['security'] = @_security unless @_security.nil?
|
76
|
+
|
77
|
+
json_array['flattenAllFormFields'] = @_flatten_all_form_fields unless @_flatten_all_form_fields.nil?
|
78
|
+
|
79
|
+
json_array['retainSignatureFormFields'] = @_retain_signature_form_fields unless @_retain_signature_form_fields.nil?
|
80
|
+
|
81
|
+
json_array['inputs'] = @_inputs
|
82
|
+
|
83
|
+
if(@_form_fields.length > 0)
|
84
|
+
json_array['formFields'] = @_form_fields
|
85
|
+
end
|
86
|
+
|
87
|
+
if(@_outlines.length > 0)
|
88
|
+
json_array['outlines'] = @_outlines
|
89
|
+
end
|
90
|
+
if(indented)
|
91
|
+
JSON.pretty_generate(json_array)
|
92
|
+
else
|
93
|
+
JSON.generate(json_array)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require_relative "Resource"
|
3
|
+
require_relative "ResourceType"
|
4
|
+
|
5
|
+
#
|
6
|
+
# Represents a pdf resource.
|
7
|
+
#
|
8
|
+
class PdfResource < Resource
|
9
|
+
#
|
10
|
+
# Initializes a new instance of the PdfResource class.
|
11
|
+
#
|
12
|
+
# @param file [String]|[Array]|[Stream] The pdf file path or the byte array of the pdf file or the stream of the pdf file.
|
13
|
+
# @param resource_name [String] The name of the resource.
|
14
|
+
#
|
15
|
+
def initialize(file, resource_name = nil)
|
16
|
+
super(file, resource_name)
|
17
|
+
@_mime_type = "application/pdf"
|
18
|
+
end
|
19
|
+
|
20
|
+
@_type = ResourceType::PDF
|
21
|
+
|
22
|
+
def _file_extension
|
23
|
+
".pdf"
|
24
|
+
end
|
25
|
+
|
26
|
+
# ?string ResourcePath
|
27
|
+
|
28
|
+
def to_json(_options = {})
|
29
|
+
@input_json = {}
|
30
|
+
@input_json["type"] = @_type
|
31
|
+
|
32
|
+
@input_json["resourceName"] = @resource_name
|
33
|
+
JSON.pretty_generate(@input_json)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require_relative 'Response'
|
3
|
+
|
4
|
+
#
|
5
|
+
# Represents the pdf response.
|
6
|
+
#
|
7
|
+
class PdfResponse < Response
|
8
|
+
#
|
9
|
+
# Gets the content od pdf.
|
10
|
+
#
|
11
|
+
attr_accessor :content
|
12
|
+
|
13
|
+
#
|
14
|
+
# Initializes a new instance of the PdfResponse class.
|
15
|
+
#
|
16
|
+
# @param pdf_content [String] The byte array of pdf content.
|
17
|
+
#
|
18
|
+
def initialize(pdf_content = nil)
|
19
|
+
super()
|
20
|
+
@content = pdf_content
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require_relative 'Endpoint'
|
3
|
+
require_relative 'PdfTextResponse'
|
4
|
+
|
5
|
+
#
|
6
|
+
# Represents the pdf text endpoint.
|
7
|
+
#
|
8
|
+
class PdfText < Endpoint
|
9
|
+
#
|
10
|
+
# Initializes a new instance of the PdfText class.
|
11
|
+
#
|
12
|
+
# @param resource [PdfResource] The image resource of type PdfResource.
|
13
|
+
# @param start_page [int] The start page.
|
14
|
+
# @param page_count [int] The page count.
|
15
|
+
#
|
16
|
+
def initialize(resource, start_page = 1, page_count = 0)
|
17
|
+
@_endpoint_name = 'pdf-text'
|
18
|
+
@start_page = 1
|
19
|
+
@page_count = 0
|
20
|
+
super()
|
21
|
+
@resource = resource
|
22
|
+
@start_page = start_page
|
23
|
+
@page_count = page_count
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Gets or sets the start page.
|
28
|
+
#
|
29
|
+
attr_accessor :start_page
|
30
|
+
|
31
|
+
#
|
32
|
+
# Gets or sets the page count.
|
33
|
+
#
|
34
|
+
attr_accessor :page_count
|
35
|
+
|
36
|
+
#
|
37
|
+
# Process the pdf resource to get pdf's text.
|
38
|
+
# @return PdfTextResponse Returns collection of PdfTextResponse.
|
39
|
+
#
|
40
|
+
def process
|
41
|
+
header = {
|
42
|
+
'Authorization': "Bearer #{@api_key}",
|
43
|
+
'Content-Length': @resource.data.length.to_s,
|
44
|
+
'Expect': '100-continue',
|
45
|
+
'Content-Type': 'application/pdf'
|
46
|
+
}
|
47
|
+
uri = URI.parse("#{@base_url}/v1.0/#{@_endpoint_name}")
|
48
|
+
params = { 'startPage' => @start_page, 'pageCount' => @page_count }
|
49
|
+
uri.query = URI.encode_www_form(params)
|
50
|
+
|
51
|
+
request = Net::HTTP::Post.new(uri.request_uri, header)
|
52
|
+
request.set_form_data(params)
|
53
|
+
req_options = {
|
54
|
+
use_ssl: uri.scheme == 'https',
|
55
|
+
verify_mode: OpenSSL::SSL::VERIFY_NONE
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
request.content_type = 'application/pdf'
|
60
|
+
request.body = @resource.data
|
61
|
+
|
62
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
63
|
+
http.request(request)
|
64
|
+
end
|
65
|
+
out_data = response.body
|
66
|
+
ret_object = PdfTextResponse.new(out_data)
|
67
|
+
ret_object.is_successful = false
|
68
|
+
ret_object.status_code = response.code
|
69
|
+
if ret_object.status_code == '200'
|
70
|
+
ret_object.is_successful = true
|
71
|
+
else
|
72
|
+
out_data_json = JSON.parse(out_data)
|
73
|
+
ret_object.error_json = out_data
|
74
|
+
ret_object.error_message = if !out_data_json['message'].nil?
|
75
|
+
out_data_json['message']
|
76
|
+
else
|
77
|
+
"status_code : #{Net::HTTPResponse::CODE_TO_OBJ[ret_object.status_code]}"
|
78
|
+
end
|
79
|
+
ret_object.error_id = out_data_json['id']
|
80
|
+
end
|
81
|
+
|
82
|
+
ret_object
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require_relative 'JsonResponse'
|
3
|
+
|
4
|
+
#
|
5
|
+
# Represents the pdf text response.
|
6
|
+
#
|
7
|
+
class PdfTextResponse < JsonResponse
|
8
|
+
#
|
9
|
+
# Initializes a new instance of the PdfResponse class.
|
10
|
+
#
|
11
|
+
# @param json_content [String] The json content
|
12
|
+
#
|
13
|
+
def initialize(json_content)
|
14
|
+
@content = JSON.pretty_generate(json_content).gsub('\\\\', '\\').gsub('\"', '"').gsub('\\\r', '\r').gsub('\\\n', '\n').gsub(
|
15
|
+
'\\\t', '\t'
|
16
|
+
)
|
17
|
+
@content = @content[1..@content.length - 2]
|
18
|
+
|
19
|
+
super(json_content)
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Gets the collection of PdfContent.
|
24
|
+
#
|
25
|
+
attr_accessor :content
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require_relative 'PdfResource'
|
3
|
+
require_relative 'Endpoint'
|
4
|
+
require_relative 'XmlResponse'
|
5
|
+
|
6
|
+
class PdfXmp < Endpoint
|
7
|
+
#
|
8
|
+
# Initializes a new instance of the PdfInfo class.
|
9
|
+
#
|
10
|
+
# @param resource [PdfResource] The resource of type PdfResource.
|
11
|
+
#
|
12
|
+
def initialize(resource)
|
13
|
+
super()
|
14
|
+
@resource = resource
|
15
|
+
@_endpoint_name = 'pdf-xmp'
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Process the pdf resource to get pdf's xmp data.
|
20
|
+
#
|
21
|
+
# @return XmlResponse Returns collection of XmlResponse.
|
22
|
+
#
|
23
|
+
def process
|
24
|
+
header = {
|
25
|
+
'Authorization': "Bearer #{@api_key}",
|
26
|
+
'Content-Length': @resource.data.length.to_s,
|
27
|
+
'Expect': '100-continue',
|
28
|
+
'Content-Type': 'application/pdf'
|
29
|
+
}
|
30
|
+
uri = URI.parse("#{@base_url}/v1.0/#{@_endpoint_name}")
|
31
|
+
|
32
|
+
request = Net::HTTP::Post.new(uri.request_uri, header)
|
33
|
+
|
34
|
+
req_options = {
|
35
|
+
use_ssl: uri.scheme == 'https',
|
36
|
+
verify_mode: OpenSSL::SSL::VERIFY_NONE
|
37
|
+
|
38
|
+
}
|
39
|
+
|
40
|
+
request.content_type = 'application/pdf'
|
41
|
+
|
42
|
+
request.body = @resource.data
|
43
|
+
|
44
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
45
|
+
http.request(request)
|
46
|
+
end
|
47
|
+
out_data = response.body
|
48
|
+
ret_object = XmlResponse.new(out_data)
|
49
|
+
ret_object.is_successful = false
|
50
|
+
ret_object.status_code = response.code
|
51
|
+
if ret_object.status_code == '200'
|
52
|
+
ret_object.is_successful = true
|
53
|
+
else
|
54
|
+
out_data_json = JSON.parse(out_data)
|
55
|
+
ret_object.error_json = out_data
|
56
|
+
ret_object.error_message = if !out_data_json['message'].nil?
|
57
|
+
out_data_json['message']
|
58
|
+
else
|
59
|
+
"status_code : #{Net::HTTPResponse::CODE_TO_OBJ[ret_object.status_code]}"
|
60
|
+
end
|
61
|
+
ret_object.error_id = out_data_json['id']
|
62
|
+
end
|
63
|
+
|
64
|
+
ret_object
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
#
|
3
|
+
# Represents information of a PushButton field.
|
4
|
+
#
|
5
|
+
class PushButtonInformation
|
6
|
+
def initialize
|
7
|
+
@name = nil
|
8
|
+
@label = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
#
|
12
|
+
# Gets or Sets the name of a PushButton field.
|
13
|
+
#
|
14
|
+
attr_accessor :name
|
15
|
+
|
16
|
+
#
|
17
|
+
# Gets or Sets the label of a PushButton field.
|
18
|
+
#
|
19
|
+
attr_accessor :label
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require_relative 'Security'
|
3
|
+
require_relative 'SecurityType'
|
4
|
+
|
5
|
+
#
|
6
|
+
# Represents RC4 128 bit PDF document security.
|
7
|
+
#
|
8
|
+
# RC4 128 bit PDF security, with UseCryptFilter property set to false is compatible with PDF version 1.4
|
9
|
+
# or higher and can be read with Adobe Acrobat Reader version 5 or higher. By default UseCryptFilter property
|
10
|
+
# is false. RC4 128 bit PDF security with crypt filter is compatible with PDF version 1.5 or higher and
|
11
|
+
# can be read with Adobe Acrobat Reader version 6 and higher. Older readers will not be able to read document
|
12
|
+
# encrypted with this security.
|
13
|
+
#
|
14
|
+
class RC4128Security < Security
|
15
|
+
#
|
16
|
+
# Initializes a new instance of the RC4128Security class.
|
17
|
+
#
|
18
|
+
# @param owner_password [String] The owner password to open the document.
|
19
|
+
# @param user_password [String] The user password to open the document.
|
20
|
+
#
|
21
|
+
def initialize(user_password, owner_password)
|
22
|
+
@_type = SecurityType::RC_4128
|
23
|
+
super(user_password, owner_password)
|
24
|
+
@encrypt_metadata = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# Gets or sets the documents components to be encrypted.
|
29
|
+
#
|
30
|
+
attr_accessor :encrypt_metadata
|
31
|
+
|
32
|
+
def to_json(_options = {})
|
33
|
+
json_array = {}
|
34
|
+
json_array['type'] = 'rc4128'
|
35
|
+
|
36
|
+
json_array['encryptMetadata'] = @encrypt_metadata unless @encrypt_metadata.nil?
|
37
|
+
|
38
|
+
#-------------------------------------------
|
39
|
+
json_array['allowCopy'] = @allow_copy unless @allow_copy.nil?
|
40
|
+
|
41
|
+
json_array['allowEdit'] = @allow_edit unless @allow_edit.nil?
|
42
|
+
|
43
|
+
json_array['allowPrint'] = @allow_print unless @allow_print.nil?
|
44
|
+
|
45
|
+
json_array['allowUpdateAnnotsAndFields'] = @allow_update_annots_and_fields unless @allow_update_annots_and_fields.nil?
|
46
|
+
|
47
|
+
json_array['ownerPassword'] = @owner_password unless @owner_password.nil?
|
48
|
+
|
49
|
+
json_array['userPassword'] = @user_password unless @user_password.nil?
|
50
|
+
|
51
|
+
json_array['allowAccessibility'] = @allow_accessibility unless @allow_accessibility.nil?
|
52
|
+
|
53
|
+
json_array['allowFormFilling'] = @allow_form_filling unless @allow_form_filling.nil?
|
54
|
+
|
55
|
+
json_array['allowHighResolutionPrinting'] = @allow_high_resolution_printing unless @allow_high_resolution_printing.nil?
|
56
|
+
|
57
|
+
json_array['allowDocumentAssembly'] = @allow_document_assembly unless @allow_document_assembly.nil?
|
58
|
+
|
59
|
+
JSON.pretty_generate(json_array)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require 'securerandom'
|
3
|
+
require_relative 'ResourceType'
|
4
|
+
require_relative 'EndPointException'
|
5
|
+
|
6
|
+
class Resource
|
7
|
+
def initialize(file = nil, resource_name = nil)
|
8
|
+
@_name = nil
|
9
|
+
@_type = nil
|
10
|
+
@_file_path = nil
|
11
|
+
@_mime_type = ''
|
12
|
+
unless file.nil?
|
13
|
+
if (file.is_a?(Array)) == true
|
14
|
+
@data = file.pack('c*')
|
15
|
+
elsif file.is_a?(String)
|
16
|
+
if File.exist?(file)
|
17
|
+
@_file_path = file
|
18
|
+
@data = Resource._get_file_data(file)
|
19
|
+
else
|
20
|
+
raise "#{file} : File does not exist."
|
21
|
+
end
|
22
|
+
else
|
23
|
+
@data = file.read
|
24
|
+
end
|
25
|
+
|
26
|
+
@resource_name = if resource_name.nil?
|
27
|
+
SecureRandom.uuid + _file_extension
|
28
|
+
else
|
29
|
+
resource_name
|
30
|
+
end
|
31
|
+
|
32
|
+
@_mime_type = ''
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_accessor :data, :_mime_type, :_file_path
|
37
|
+
|
38
|
+
#
|
39
|
+
# Gets or sets the resource name.
|
40
|
+
#
|
41
|
+
attr_accessor :resource_name
|
42
|
+
|
43
|
+
def _file_extension
|
44
|
+
File.extname(@_file_path) unless @_file_path.nil?
|
45
|
+
end
|
46
|
+
|
47
|
+
def self._get_file_data(file_path)
|
48
|
+
File.binread(file_path)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
#
|
3
|
+
#
|
4
|
+
# Specifies resource type.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
class ResourceType
|
8
|
+
#
|
9
|
+
# Image resource.
|
10
|
+
#
|
11
|
+
IMAGE = "Image".freeze
|
12
|
+
|
13
|
+
#
|
14
|
+
# Pdf resource.
|
15
|
+
#
|
16
|
+
PDF = "Pdf".freeze
|
17
|
+
|
18
|
+
#
|
19
|
+
# LayoutData resource.
|
20
|
+
#
|
21
|
+
LAYOUT_DATA = "LayoutData".freeze
|
22
|
+
|
23
|
+
#
|
24
|
+
# Dlex resource.
|
25
|
+
#
|
26
|
+
DLEX = "Dlex".freeze
|
27
|
+
|
28
|
+
#
|
29
|
+
# Font resource.
|
30
|
+
#
|
31
|
+
FONT = "Font".freeze
|
32
|
+
|
33
|
+
#
|
34
|
+
# Html resource.
|
35
|
+
#
|
36
|
+
HTML = "Html".freeze
|
37
|
+
|
38
|
+
#
|
39
|
+
# Word resource.
|
40
|
+
#
|
41
|
+
WORD = "Word".freeze
|
42
|
+
|
43
|
+
#
|
44
|
+
# Excel resource.
|
45
|
+
#
|
46
|
+
EXCEL = "Excel".freeze
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
#
|
3
|
+
# Represents the base class for response.
|
4
|
+
#
|
5
|
+
class Response
|
6
|
+
def initialize
|
7
|
+
@_is_successful = false
|
8
|
+
@_error_message = nil
|
9
|
+
@_error_id = nil
|
10
|
+
@_status_code = nil
|
11
|
+
@_error_json = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
# Gets the boolean, indicating the response's status.
|
16
|
+
#
|
17
|
+
attr_accessor :is_successful
|
18
|
+
|
19
|
+
#
|
20
|
+
# Gets the error message.
|
21
|
+
#
|
22
|
+
attr_accessor :error_message
|
23
|
+
|
24
|
+
#
|
25
|
+
# Gets the error id.
|
26
|
+
#
|
27
|
+
attr_accessor :error_id
|
28
|
+
|
29
|
+
#
|
30
|
+
# Gets the status code.
|
31
|
+
#
|
32
|
+
attr_accessor :status_code
|
33
|
+
|
34
|
+
#
|
35
|
+
# Gets the error json.
|
36
|
+
#
|
37
|
+
attr_accessor :error_json
|
38
|
+
end
|
39
|
+
end
|