dynamicpdf_api 1.2.1 → 2.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0680c136fd344450e1b3f772c0ec4094781342bdee3114037fc27de04c036a8a'
4
- data.tar.gz: 4b5541b2b8d47dabc56c894857d1bf2fad98b53c770023d080ef7ac096fa4306
3
+ metadata.gz: 5427fc35251fa21f680fdba436398a94022ed793ce0a614d15be5712fc5801be
4
+ data.tar.gz: b079a50d26fc63e33089f3145e5e5d94ca2954e0a8ece78e73321dfc39ef0110
5
5
  SHA512:
6
- metadata.gz: 1b8c8d62491859abfbb0bc5718fd9594b969e0689b5abd369fc283afca882186370e0bbe1e6edc311a98370e259d01443016fbd6e048e6e4ca6b544069af856e
7
- data.tar.gz: 9b104c7ea32e0a9f35cf3468eae12fb395d8f8a42ffa04b0894253d0e52b81323ada51db32ce83602a04d21482238572ca42cf3d81dc732795cb3fc0a68f0a29
6
+ metadata.gz: d1d477bc4deab58568ffc065d051a020dff8621fea17ad8fc76ee16322a47df37b0b370ecdbc23f4e2a21bb361577683ff5da328ccb0925497f94746206dd017
7
+ data.tar.gz: 486dbe03715475af148d3684d083b4c88493df7588cff4994d0c9838e22990e4b22f8d256c27084750b12094b41d480c9c932d4ab572fc0a6d492e3ec4a3c507
@@ -29,6 +29,7 @@ module DynamicPDFApi
29
29
  #
30
30
  attr_accessor :x_dimension
31
31
 
32
+ protected
32
33
  #
33
34
  # Gets or sets the value of the barcode.
34
35
  #
@@ -16,7 +16,7 @@ module DynamicPDFApi
16
16
  else
17
17
  super(value, placement, x_offset, y_offset)
18
18
  @_value_type = ValueType::BASE64_ENCODED_BYTES
19
- @value = Base64.encode64(value.pack('C*'))
19
+ @value = Base64.strict_encode64(value.pack('C*'))
20
20
  @placement = placement
21
21
  @x_offset = x_offset
22
22
  @y_offset = y_offset
@@ -0,0 +1,31 @@
1
+ module DynamicPDFApi
2
+ #
3
+ # Specifies Encryption Type.
4
+ #
5
+ class EncryptionType
6
+ #
7
+ # RC4 40 bit security.
8
+ #
9
+ RC440 = 'rc440'.freeze
10
+
11
+ #
12
+ # RC4 128 bit security.
13
+ #
14
+ RC4128 = 'rc4128'.freeze
15
+
16
+ #
17
+ # AES 128 bit security with CBC cipher mode.
18
+ #
19
+ AES128CBC = 'aes128cbc'.freeze
20
+
21
+ #
22
+ # AES 256 bit security with CBC cipher mode.
23
+ #
24
+ AES256CBC = 'aes256cbc'.freeze
25
+
26
+ #
27
+ # No security.
28
+ #
29
+ NONE = 'none'.freeze
30
+ end
31
+ end
@@ -10,12 +10,55 @@ module DynamicPDFApi
10
10
  @load_required = true
11
11
  @lock = Mutex.new
12
12
 
13
- # For Windows fonts
14
- windir = ENV["WINDIR"]
15
- if windir && !windir.empty?
16
- @path_to_fonts_resource_directory = File.join(windir, "Fonts")
17
- else
18
- @path_to_fonts_resource_directory = nil
13
+ def self.init(platform_override = nil)
14
+ begin
15
+
16
+ # -------- Windows --------
17
+ if RUBY_PLATFORM =~ /mswin|mingw|cygwin/
18
+ windir = ENV["WINDIR"]
19
+ if windir && !windir.empty?
20
+ path = File.join(windir, "Fonts")
21
+ @path_to_fonts_resource_directory = path if Dir.exist?(path)
22
+ end
23
+
24
+ # -------- macOS --------
25
+ elsif RUBY_PLATFORM =~ /darwin/
26
+ home = Dir.home rescue nil
27
+ paths = [
28
+ "/System/Library/Fonts",
29
+ "/Library/Fonts",
30
+ home ? File.join(home, "Library", "Fonts") : nil
31
+ ]
32
+
33
+ paths.each do |path|
34
+ next unless path
35
+ if Dir.exist?(path)
36
+ @path_to_fonts_resource_directory = path
37
+ break
38
+ end
39
+ end
40
+
41
+ # -------- Linux --------
42
+ elsif RUBY_PLATFORM =~ /linux/
43
+ home = Dir.home rescue nil
44
+ paths = [
45
+ "/usr/share/fonts",
46
+ "/usr/local/share/fonts",
47
+ home ? File.join(home, ".fonts") : nil,
48
+ home ? File.join(home, ".local", "share", "fonts") : nil
49
+ ]
50
+
51
+ paths.each do |path|
52
+ next unless path
53
+ if Dir.exist?(path)
54
+ @path_to_fonts_resource_directory = path
55
+ break
56
+ end
57
+ end
58
+ end
59
+ rescue e
60
+ puts "Error in getting the font: #{e.message}"
61
+ end
19
62
  end
20
63
 
21
64
  #
@@ -279,6 +322,8 @@ module DynamicPDFApi
279
322
  return unless @load_required
280
323
  loaded_any = false
281
324
 
325
+ init
326
+
282
327
  @lock.synchronize do
283
328
  if @path_to_fonts_resource_directory && !@path_to_fonts_resource_directory.empty?
284
329
  dir_Info = File.join(@path_to_fonts_resource_directory.gsub("\\", "/"), "*")
@@ -223,17 +223,20 @@ module DynamicPDFApi
223
223
  #
224
224
  # Returns a page_input object containing the input pdf.
225
225
  #
226
- # @param page_width [float] The width of the page.
227
- # @param page_height [float] The height of the page.
226
+ # @param size [String]|[Float] The size of the page or The width of the page.
227
+ # @param orientation [String]|[Float] The orientation of the page or The height of the page.
228
+ # @param margins [Float] The margins of the page.
228
229
  #
229
- # @return page_input page_input object.
230
+ # @return PageInput PageInput object.
230
231
  #
231
- def add_page(page_width = nil, page_height = nil)
232
- input = if !page_width.nil? && !page_height.nil?
233
- PageInput.new(page_width, page_height)
234
- else
235
- PageInput.new
236
- end
232
+ def add_page(size = nil, orientation = nil, margins = nil)
233
+ if (size.is_a?(String) || size.nil?) && (orientation.is_a?(String) || orientation.nil?)
234
+ input = PageInput.new(size, orientation, margins)
235
+ elsif (size.is_a?(Numeric)) && (orientation.is_a?(Numeric))
236
+ input = PageInput.new(size, orientation)
237
+ else
238
+ input = PageInput.new
239
+ end
237
240
  @inputs << input
238
241
  input
239
242
  end
@@ -0,0 +1,102 @@
1
+ module DynamicPDFApi
2
+ require_relative 'EncryptionType'
3
+
4
+ # Represents the PDF security info endpoint.
5
+ class PdfSecurityInfo
6
+ def initialize(data = {})
7
+ @encryption_type_string = data["encryptionType"]
8
+ @allow_edit = data["allowEdit"]
9
+ @allow_print = data["allowPrint"]
10
+ @allow_update_annots_and_fields = data["allowUpdateAnnotsAndFields"]
11
+ @allow_copy = data["allowCopy"]
12
+ @allow_high_resolution_printing = data["allowHighResolutionPrinting"]
13
+ @allow_document_assembly = data["allowDocumentAssembly"]
14
+ @allow_form_filling = data["allowFormFilling"]
15
+ @allow_accessibility = data["allowAccessibility"]
16
+ @encrypt_all_except_metadata = data["encryptAllExceptMetadata"]
17
+ @encrypt_only_file_attachments = data["encryptOnlyFileAttachments"]
18
+ @has_owner_password = data["hasOwnerPassword"]
19
+ @has_user_password = data["hasUserPassword"]
20
+ @encryption_type = encryption_type()
21
+ end
22
+
23
+ #
24
+ # Gets or sets if the document can be edited by the user.
25
+ #
26
+ attr_accessor :allow_edit
27
+
28
+ #
29
+ # Gets or sets if the document can be printed by the user.
30
+ #
31
+ attr_accessor :allow_print
32
+
33
+ #
34
+ # Gets or sets if annotations and form fields can be added, edited and modified by the user.
35
+ #
36
+ attr_accessor :allow_update_annots_and_fields
37
+
38
+ #
39
+ # Gets or sets if text and images can be copied to the clipboard by the user.
40
+ #
41
+ attr_accessor :allow_copy
42
+
43
+ #
44
+ # Gets or sets if the document can be printed at a high resolution by the user.
45
+ #
46
+ attr_accessor :allow_high_resolution_printing
47
+
48
+ #
49
+ # Gets or sets if the document can be assembled and manipulated by the user.
50
+ #
51
+ attr_accessor :allow_document_assembly
52
+
53
+ #
54
+ # Gets or sets if form filling should be allowed by the user.
55
+ #
56
+ attr_accessor :allow_form_filling
57
+
58
+ #
59
+ # Gets or sets if accessibility programs should be able to read the documents text and images for the user.
60
+ #
61
+ attr_accessor :allow_accessibility
62
+
63
+ #
64
+ # Gets or sets a value indicating whether all data should be encrypted except for metadata.
65
+ #
66
+ attr_accessor :encrypt_all_except_metadata
67
+
68
+ #
69
+ # Gets or sets a value indicating whether only file attachments should be encrypted.
70
+ #
71
+ attr_accessor :encrypt_only_file_attachments
72
+
73
+ #
74
+ # Gets or sets a value indicating whether the PDF document has an owner password set.
75
+ #
76
+ attr_accessor :has_owner_password
77
+
78
+ #
79
+ # Gets or sets a value indicating whether the PDF document has an user password set.
80
+ #
81
+ attr_accessor :has_user_password
82
+
83
+
84
+ # Gets or sets the encryption type.
85
+ attr_accessor :encryption_type_string
86
+
87
+ def encryption_type
88
+ case (@encryption_type_string).downcase
89
+ when "rc4-40"
90
+ EncryptionType::RC440
91
+ when "rc4-128"
92
+ EncryptionType::RC4128
93
+ when "aes-128-cbc"
94
+ EncryptionType::AES128CBC
95
+ when "aes-256-cbc"
96
+ EncryptionType::AES256CBC
97
+ else
98
+ EncryptionType::NONE
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,71 @@
1
+ module DynamicPDFApi
2
+ require_relative 'Endpoint'
3
+ require_relative 'PdfSecurityInfoResponse'
4
+
5
+ #
6
+ # Represents the pdf security info endpoint.
7
+ #
8
+ class PdfSecurityInfoEndpoint < Endpoint
9
+ #
10
+ # Initializes a new instance of the PdfSecurityInfoEndpoint 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-security-info'
18
+ end
19
+
20
+ #
21
+ # Process the pdf resource to get pdf's security information.
22
+ # @return PdfInfoResponse Returns collection of PdfSecurityInfoResponse.
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 = PdfSecurityInfoResponse.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
+ if ret_object.status_code == '401'
56
+ raise "Invalid api key specified."
57
+ end
58
+ out_data_json = JSON.parse(out_data)
59
+ ret_object.error_json = out_data
60
+ ret_object.error_message = if !out_data_json['message'].nil?
61
+ out_data_json['message']
62
+ else
63
+ "status_code : #{Net::HTTPResponse::CODE_TO_OBJ[ret_object.status_code]}"
64
+ end
65
+ ret_object.error_id = out_data_json['id']
66
+ end
67
+
68
+ ret_object
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,28 @@
1
+ module DynamicPDFApi
2
+ require_relative 'JsonResponse'
3
+ require_relative 'PdfSecurityInfo'
4
+
5
+ #
6
+ # Represents the pdf security info response.
7
+ #
8
+ class PdfSecurityInfoResponse < JsonResponse
9
+ #
10
+ # Initializes a new instance of the PdfSecurityInfoResponse class.
11
+ #
12
+ # @param json_content [String] The json content
13
+ #
14
+ def initialize(json_content = nil)
15
+ @content = nil
16
+ super(json_content) unless json_content.nil?
17
+ @content = PdfSecurityInfo.new(JSON.parse(json_content))
18
+
19
+ end
20
+ # # @content.instance_variable_set(:@encryption_type, @content.encryption_type)
21
+ # end
22
+
23
+ #
24
+ # Gets the collection of PdfContent.
25
+ #
26
+ attr_accessor :content
27
+ end
28
+ end
@@ -18,6 +18,6 @@ module DynamicPDFApi
18
18
  #
19
19
  # RC4 128 bit security.
20
20
  #
21
- RC_4128 = 'aC4128'.freeze
21
+ RC_4128 = 'rc4128'.freeze
22
22
  end
23
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyClient
4
- VERSION = "1.2.1"
4
+ VERSION = "2.0.0"
5
5
  end
data/lib/ruby_client.rb CHANGED
@@ -16,6 +16,7 @@ require_relative "ruby_client/DlexInput.rb"
16
16
  require_relative "ruby_client/DlexLayout.rb"
17
17
  require_relative "ruby_client/DlexResource.rb"
18
18
  require_relative "ruby_client/EncryptDocumentComponents.rb"
19
+ require_relative "ruby_client/EncryptionType.rb"
19
20
  require_relative "ruby_client/Endpoint.rb"
20
21
  require_relative "ruby_client/EndPointException.rb"
21
22
  require_relative "ruby_client/EndpointResource.rb"
@@ -59,6 +60,9 @@ require_relative "ruby_client/PdfInput.rb"
59
60
  require_relative "ruby_client/PdfInstructions.rb"
60
61
  require_relative "ruby_client/PdfResource.rb"
61
62
  require_relative "ruby_client/PdfResponse.rb"
63
+ require_relative "ruby_client/PdfSecurityInfo.rb"
64
+ require_relative "ruby_client/PdfSecurityInfoEndpoint.rb"
65
+ require_relative "ruby_client/PdfSecurityInfoResponse.rb"
62
66
  require_relative "ruby_client/PdfText.rb"
63
67
  require_relative "ruby_client/PdfTextResponse.rb"
64
68
  require_relative "ruby_client/PdfXmp.rb"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamicpdf_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dynamicpdf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-09-29 00:00:00.000000000 Z
11
+ date: 2026-02-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Ruby Client API that uses the DynamicPDF API to create, merge, split,
14
14
  form fill, stamp, secure/encrypt PDF documents and convert word/Excel files to PDF.
@@ -72,6 +72,7 @@ files:
72
72
  - lib/ruby_client/Elements/TextElement.rb
73
73
  - lib/ruby_client/Elements/ValueType.rb
74
74
  - lib/ruby_client/EncryptDocumentComponents.rb
75
+ - lib/ruby_client/EncryptionType.rb
75
76
  - lib/ruby_client/EndPointException.rb
76
77
  - lib/ruby_client/Endpoint.rb
77
78
  - lib/ruby_client/EndpointResource.rb
@@ -146,6 +147,9 @@ files:
146
147
  - lib/ruby_client/PdfInstructions.rb
147
148
  - lib/ruby_client/PdfResource.rb
148
149
  - lib/ruby_client/PdfResponse.rb
150
+ - lib/ruby_client/PdfSecurityInfo.rb
151
+ - lib/ruby_client/PdfSecurityInfoEndpoint.rb
152
+ - lib/ruby_client/PdfSecurityInfoResponse.rb
149
153
  - lib/ruby_client/PdfText.rb
150
154
  - lib/ruby_client/PdfTextResponse.rb
151
155
  - lib/ruby_client/PdfXmp.rb