dynamicpdf_api 1.1.2 → 1.2.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.
- checksums.yaml +4 -4
- data/lib/ruby_client/AdditionalResource.rb +6 -6
- data/lib/ruby_client/Font.rb +77 -0
- data/lib/ruby_client/FontInformation.rb +4 -3
- data/lib/ruby_client/FullNameTable.rb +67 -0
- data/lib/ruby_client/Imaging/PdfImage.rb +2 -1
- data/lib/ruby_client/Pdf.rb +6 -3
- data/lib/ruby_client/PdfText.rb +10 -4
- data/lib/ruby_client/PdfTextResponse.rb +6 -6
- data/lib/ruby_client/Security.rb +11 -11
- data/lib/ruby_client/TextOrder.rb +21 -0
- data/lib/ruby_client/version.rb +1 -1
- data/lib/ruby_client.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0680c136fd344450e1b3f772c0ec4094781342bdee3114037fc27de04c036a8a'
|
4
|
+
data.tar.gz: 4b5541b2b8d47dabc56c894857d1bf2fad98b53c770023d080ef7ac096fa4306
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b8c8d62491859abfbb0bc5718fd9594b969e0689b5abd369fc283afca882186370e0bbe1e6edc311a98370e259d01443016fbd6e048e6e4ca6b544069af856e
|
7
|
+
data.tar.gz: 9b104c7ea32e0a9f35cf3468eae12fb395d8f8a42ffa04b0894253d0e52b81323ada51db32ce83602a04d21482238572ca42cf3d81dc732795cb3fc0a68f0a29
|
@@ -36,17 +36,11 @@ module DynamicPDFApi
|
|
36
36
|
@type = ResourceType::FONT
|
37
37
|
|
38
38
|
when ".tiff"
|
39
|
-
@type = ResourceType::IMAGE
|
40
39
|
when ".tif"
|
41
|
-
@type = ResourceType::IMAGE
|
42
40
|
when ".png"
|
43
|
-
@type = ResourceType::IMAGE
|
44
41
|
when ".gif"
|
45
|
-
@type = ResourceType::IMAGE
|
46
42
|
when ".jpeg"
|
47
|
-
@type = ResourceType::IMAGE
|
48
43
|
when ".jpg"
|
49
|
-
@type = ResourceType::IMAGE
|
50
44
|
when ".bmp"
|
51
45
|
@type = ResourceType::IMAGE
|
52
46
|
|
@@ -66,16 +60,22 @@ module DynamicPDFApi
|
|
66
60
|
@file_header = @file_header.bytes
|
67
61
|
if (ImageResource.is_png_image(@file_header))
|
68
62
|
@_mime_type = "image/png"
|
63
|
+
".png"
|
69
64
|
elsif (ImageResource.is_jpeg_image(@file_header))
|
70
65
|
@_mime_type = "image/jpeg"
|
66
|
+
".jpeg"
|
71
67
|
elsif (ImageResource.is_gif_image(@file_header))
|
72
68
|
@_mime_type = "image/gif"
|
69
|
+
".gif"
|
73
70
|
elsif (ImageResource.is_tiff_image(@file_header))
|
74
71
|
@_mime_type = "image/tiff"
|
72
|
+
".tiff"
|
75
73
|
elsif (ImageResource.is_jpeg2000_image(@file_header))
|
76
74
|
@_mime_type = "image/jpeg"
|
75
|
+
".jpeg"
|
77
76
|
elsif (ImageResource.is_valid_bitmap_image(@file_header))
|
78
77
|
@_mime_type = "image/bmp"
|
78
|
+
".bmp"
|
79
79
|
else
|
80
80
|
raise "Not supported image type or invalid image."
|
81
81
|
end
|
data/lib/ruby_client/Font.rb
CHANGED
@@ -1,10 +1,23 @@
|
|
1
1
|
module DynamicPDFApi
|
2
2
|
require_relative "FontResource"
|
3
|
+
require_relative "FullNameTable"
|
3
4
|
|
4
5
|
#
|
5
6
|
# Represents font.
|
6
7
|
#
|
7
8
|
class Font
|
9
|
+
@font_details = []
|
10
|
+
@load_required = true
|
11
|
+
@lock = Mutex.new
|
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
|
19
|
+
end
|
20
|
+
|
8
21
|
#
|
9
22
|
# Initializes a new instance of the Font class using the font name that is present in the cloud resource
|
10
23
|
# manager.
|
@@ -245,6 +258,70 @@ module DynamicPDFApi
|
|
245
258
|
font
|
246
259
|
end
|
247
260
|
|
261
|
+
def self.from_system(font_name, resource_name = nil)
|
262
|
+
return nil if font_name.nil? || font_name.strip.empty?
|
263
|
+
|
264
|
+
font_name = font_name.gsub(/[- ]/, "") # Removing the space and - from font_name
|
265
|
+
|
266
|
+
self.load_fonts if @load_required
|
267
|
+
|
268
|
+
@font_details.each do |detail|
|
269
|
+
if detail._name.casecmp(font_name).zero?
|
270
|
+
font_resource = FontResource.new(detail.file_path, resource_name)
|
271
|
+
return Font.create_font(font_resource, font_resource.resource_name)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
nil
|
276
|
+
end
|
277
|
+
|
278
|
+
def self.load_fonts
|
279
|
+
return unless @load_required
|
280
|
+
loaded_any = false
|
281
|
+
|
282
|
+
@lock.synchronize do
|
283
|
+
if @path_to_fonts_resource_directory && !@path_to_fonts_resource_directory.empty?
|
284
|
+
dir_Info = File.join(@path_to_fonts_resource_directory.gsub("\\", "/"), "*")
|
285
|
+
|
286
|
+
Dir.glob(dir_Info).each do |file_path|
|
287
|
+
next unless file_path.downcase.end_with?(".ttf", ".otf")
|
288
|
+
|
289
|
+
File.open(file_path, "rb") do |reader|
|
290
|
+
name_table = self.read_font_name_table(reader)
|
291
|
+
|
292
|
+
if name_table && name_table._name && !name_table._name.empty?
|
293
|
+
@font_details << FontInformation.new(name_table._name, file_path)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
@load_required = false
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
def self.read_font_name_table(reader)
|
303
|
+
name_table = nil
|
304
|
+
begin
|
305
|
+
reader.seek(4, IO::SEEK_SET)
|
306
|
+
table_count = (reader.readbyte << 8) | reader.readbyte
|
307
|
+
if table_count > 0
|
308
|
+
reader.seek(12, IO::SEEK_SET)
|
309
|
+
table_directory = reader.read(table_count * 16).b
|
310
|
+
(0...table_directory.size).step(16) do |i|
|
311
|
+
tag_bytes = table_directory[i, 4]
|
312
|
+
tag = tag_bytes.unpack1("V")
|
313
|
+
if tag == 1701667182 # "name"
|
314
|
+
name_table = FullNameTable.new(reader, table_directory, i)
|
315
|
+
break
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
rescue => e
|
320
|
+
puts "Error in read_font_name_table: #{e.message}"
|
321
|
+
end
|
322
|
+
name_table
|
323
|
+
end
|
324
|
+
|
248
325
|
def to_json(_options = {})
|
249
326
|
json_array = {}
|
250
327
|
json_array["name"] = @_name unless @_name.nil?
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module DynamicPDFApi
|
2
2
|
class FontInformation
|
3
|
-
|
4
|
-
@_font_name = font_name
|
3
|
+
attr_reader :_name, :file_path
|
5
4
|
|
6
|
-
|
5
|
+
def initialize(font_name, file_path)
|
6
|
+
@_name = font_name
|
7
|
+
@file_path = file_path
|
7
8
|
end
|
8
9
|
end
|
9
10
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require "stringio"
|
3
|
+
|
4
|
+
class FullNameTable
|
5
|
+
attr_reader :_name
|
6
|
+
def initialize(io, table_directory, position)
|
7
|
+
|
8
|
+
if table_directory != nil
|
9
|
+
int_offset = read_ulong(table_directory, position + 8)
|
10
|
+
int_length = read_ulong(table_directory, position + 12)
|
11
|
+
|
12
|
+
io.seek(int_offset, IO::SEEK_SET)
|
13
|
+
@data = io.read(int_length).b
|
14
|
+
end
|
15
|
+
|
16
|
+
@_name = ""
|
17
|
+
|
18
|
+
dataStart = read_ushort(4)
|
19
|
+
headerStart = 6
|
20
|
+
headerEnd = (read_ushort(2)* 12)
|
21
|
+
|
22
|
+
(headerStart...headerEnd).step(12) do |i|
|
23
|
+
if read_ushort(i + 6) == 4 # 4 is the Name ID for Full font name
|
24
|
+
if read_ushort(i) == 3 && read_ushort(i + 2) == 1 && read_ushort(i + 4) == 0x0409 # 3 for PlatForm ID, 1 for Encoding ID and 0x0409 Language ID for English(United States)
|
25
|
+
offset = read_ushort(i + 10)
|
26
|
+
length = read_ushort(i + 8)
|
27
|
+
raw_bytes = @data[dataStart + offset, length]
|
28
|
+
if raw_bytes
|
29
|
+
decoded = raw_bytes.dup.force_encoding("UTF-16BE").encode("UTF-8", invalid: :replace, undef: :replace).strip
|
30
|
+
@_name = decoded
|
31
|
+
break unless @_name.empty?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if @_name.empty?
|
38
|
+
(headerStart...headerEnd).step(12) do |i|
|
39
|
+
if read_ushort(i + 6) == 4 # 4 is the Name ID for Full font name
|
40
|
+
if read_ushort(i) == 3 # 3 for PlatForm ID, 0 for Encoding ID and 0x0409 Language ID for English(United States)
|
41
|
+
offset = read_ushort(i + 10)
|
42
|
+
length = read_ushort(i + 8)
|
43
|
+
raw_bytes = @data[dataStart + offset, length]
|
44
|
+
if raw_bytes
|
45
|
+
decoded = raw_bytes.dup.force_encoding("UTF-16BE").encode("UTF-8", invalid: :replace, undef: :replace).strip
|
46
|
+
@_name = decoded
|
47
|
+
break
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Remove spaces and hyphens
|
55
|
+
@_name.gsub!(/[ -]/, "") unless @_name.nil?
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def read_ushort(index)
|
60
|
+
@data[index, 2]&.unpack1("n") || 0
|
61
|
+
end
|
62
|
+
|
63
|
+
def read_ulong(array, index)
|
64
|
+
array[index, 4].unpack1("N")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/ruby_client/Pdf.rb
CHANGED
@@ -170,7 +170,7 @@ module DynamicPDFApi
|
|
170
170
|
#
|
171
171
|
def add_html(html, basepath = nil, size = nil, orientation = nil, margins = nil)
|
172
172
|
input = nil
|
173
|
-
if
|
173
|
+
if html.is_a?(String)
|
174
174
|
input = HtmlInput.new(HtmlResource.new(html), basepath, size, orientation, margins)
|
175
175
|
else
|
176
176
|
input = HtmlInput.new(resource, basepath, size, orientation, margins)
|
@@ -339,8 +339,11 @@ module DynamicPDFApi
|
|
339
339
|
}
|
340
340
|
|
341
341
|
resource_array = []
|
342
|
-
|
343
|
-
|
342
|
+
json_bytes = data_string.encode("UTF-8") # UTF-8 text
|
343
|
+
resource_array << ["Instructions",json_bytes.force_encoding("ASCII-8BIT"), # send as binary even if UTF-8 text
|
344
|
+
{ content_type: "application/json", filename: "Instructions.json" }
|
345
|
+
]
|
346
|
+
|
344
347
|
@resources.each_value do |field|
|
345
348
|
data = if !field._file_path.nil?
|
346
349
|
File.binread(field._file_path)
|
data/lib/ruby_client/PdfText.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module DynamicPDFApi
|
2
2
|
require_relative 'Endpoint'
|
3
3
|
require_relative 'PdfTextResponse'
|
4
|
+
require_relative 'TextOrder'
|
4
5
|
|
5
6
|
#
|
6
7
|
# Represents the pdf text endpoint.
|
@@ -12,15 +13,15 @@ module DynamicPDFApi
|
|
12
13
|
# @param resource [PdfResource] The image resource of type PdfResource.
|
13
14
|
# @param start_page [int] The start page.
|
14
15
|
# @param page_count [int] The page count.
|
16
|
+
# @param text_order The text extraction order.
|
15
17
|
#
|
16
|
-
def initialize(resource, start_page = 1, page_count = 0)
|
18
|
+
def initialize(resource, start_page = 1, page_count = 0, text_order = TextOrder::STREAM)
|
17
19
|
@_endpoint_name = 'pdf-text'
|
18
|
-
@start_page = 1
|
19
|
-
@page_count = 0
|
20
20
|
super()
|
21
21
|
@resource = resource
|
22
22
|
@start_page = start_page
|
23
23
|
@page_count = page_count
|
24
|
+
@text_order = text_order
|
24
25
|
end
|
25
26
|
|
26
27
|
#
|
@@ -33,6 +34,11 @@ module DynamicPDFApi
|
|
33
34
|
#
|
34
35
|
attr_accessor :page_count
|
35
36
|
|
37
|
+
#
|
38
|
+
# Gets or sets the text extraction order.
|
39
|
+
#
|
40
|
+
attr_accessor :text_order
|
41
|
+
|
36
42
|
#
|
37
43
|
# Process the pdf resource to get pdf's text.
|
38
44
|
# @return PdfTextResponse Returns collection of PdfTextResponse.
|
@@ -45,7 +51,7 @@ module DynamicPDFApi
|
|
45
51
|
'Content-Type': 'application/pdf'
|
46
52
|
}
|
47
53
|
uri = URI.parse("#{@base_url}/v1.0/#{@_endpoint_name}")
|
48
|
-
params = { 'startPage' => @start_page, 'pageCount' => @page_count }
|
54
|
+
params = { 'startPage' => @start_page, 'pageCount' => @page_count, 'textOrder' => @text_order }
|
49
55
|
uri.query = URI.encode_www_form(params)
|
50
56
|
|
51
57
|
request = Net::HTTP::Post.new(uri.request_uri, header)
|
@@ -10,13 +10,13 @@ module DynamicPDFApi
|
|
10
10
|
#
|
11
11
|
# @param json_content [String] The json content
|
12
12
|
#
|
13
|
-
def initialize(json_content)
|
14
|
-
|
15
|
-
|
16
|
-
)
|
17
|
-
|
13
|
+
def initialize(json_content = nil)
|
14
|
+
|
15
|
+
@content = nil
|
16
|
+
super(json_content) unless json_content.nil?
|
17
|
+
|
18
|
+
@content = JSON.parse(json_content)
|
18
19
|
|
19
|
-
super(json_content)
|
20
20
|
end
|
21
21
|
|
22
22
|
#
|
data/lib/ruby_client/Security.rb
CHANGED
@@ -6,18 +6,18 @@ module DynamicPDFApi
|
|
6
6
|
#
|
7
7
|
class Security
|
8
8
|
def initialize(user_pwd = nil, owner_pwd = nil)
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
9
|
+
@user_password = user_pwd
|
10
|
+
@owner_password = owner_pwd
|
11
|
+
@allow_copy = nil
|
12
|
+
@allow_edit = nil
|
13
|
+
@allow_print = nil
|
14
|
+
@allow_update_annots_and_fields = nil
|
15
15
|
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@
|
16
|
+
@allow_accessibility = nil
|
17
|
+
@allow_form_filling = nil
|
18
|
+
@allow_high_resolution_printing = nil
|
19
|
+
@allow_document_assembly = nil
|
20
|
+
@type = nil
|
21
21
|
end
|
22
22
|
|
23
23
|
#
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
#
|
3
|
+
#
|
4
|
+
# Specifies text extraction order.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
class TextOrder
|
8
|
+
#
|
9
|
+
# Stream text extraction order.
|
10
|
+
#
|
11
|
+
STREAM = "Stream".freeze
|
12
|
+
#
|
13
|
+
# Visible text extraction order.
|
14
|
+
#
|
15
|
+
VISIBLE = "Visible".freeze
|
16
|
+
#
|
17
|
+
# VisibleExtraSpace text extraction order.
|
18
|
+
#
|
19
|
+
VISIBLE_EXTRA_SPACE = "VisibleExtraSpace".freeze
|
20
|
+
end
|
21
|
+
end
|
data/lib/ruby_client/version.rb
CHANGED
data/lib/ruby_client.rb
CHANGED
@@ -26,6 +26,7 @@ require_relative "ruby_client/FontInformation.rb"
|
|
26
26
|
require_relative "ruby_client/FontResource.rb"
|
27
27
|
require_relative "ruby_client/FormField.rb"
|
28
28
|
require_relative "ruby_client/FormFieldInformation.rb"
|
29
|
+
require_relative "ruby_client/FullNameTable.rb"
|
29
30
|
require_relative "ruby_client/GoToAction.rb"
|
30
31
|
require_relative "ruby_client/Grayscale.rb"
|
31
32
|
require_relative "ruby_client/HtmlInput.rb"
|
@@ -72,6 +73,7 @@ require_relative "ruby_client/SecurityType.rb"
|
|
72
73
|
require_relative "ruby_client/SignatureFieldInformation.rb"
|
73
74
|
require_relative "ruby_client/Template.rb"
|
74
75
|
require_relative "ruby_client/TextFieldInformation.rb"
|
76
|
+
require_relative "ruby_client/TextOrder.rb"
|
75
77
|
require_relative "ruby_client/TextReplace.rb"
|
76
78
|
require_relative "ruby_client/UrlAction.rb"
|
77
79
|
require_relative "ruby_client/UnitConverter.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.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dynamicpdf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-09-29 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.
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/ruby_client/FontResource.rb
|
83
83
|
- lib/ruby_client/FormField.rb
|
84
84
|
- lib/ruby_client/FormFieldInformation.rb
|
85
|
+
- lib/ruby_client/FullNameTable.rb
|
85
86
|
- lib/ruby_client/GoToAction.rb
|
86
87
|
- lib/ruby_client/Grayscale.rb
|
87
88
|
- lib/ruby_client/HtmlInput.rb
|
@@ -159,6 +160,7 @@ files:
|
|
159
160
|
- lib/ruby_client/SignatureFieldInformation.rb
|
160
161
|
- lib/ruby_client/Template.rb
|
161
162
|
- lib/ruby_client/TextFieldInformation.rb
|
163
|
+
- lib/ruby_client/TextOrder.rb
|
162
164
|
- lib/ruby_client/TextReplace.rb
|
163
165
|
- lib/ruby_client/UnitConverter.rb
|
164
166
|
- lib/ruby_client/UrlAction.rb
|