asposecloudsdk 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.project +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/asposecloudsdk.gemspec +24 -0
- data/lib/Barcode/builder.rb +31 -0
- data/lib/Barcode/reader.rb +87 -0
- data/lib/Cells/chart_editor.rb +145 -0
- data/lib/Cells/convertor.rb +225 -0
- data/lib/Cells/extractor.rb +155 -0
- data/lib/Cells/text_editor.rb +99 -0
- data/lib/Cells/workbook.rb +437 -0
- data/lib/Cells/worksheet.rb +819 -0
- data/lib/Common/aspose_app.rb +14 -0
- data/lib/Common/product.rb +17 -0
- data/lib/Common/utils.rb +108 -0
- data/lib/Ocr/extractor.rb +128 -0
- data/lib/Pdf/annotation_editor.rb +533 -0
- data/lib/Pdf/converter.rb +201 -0
- data/lib/Pdf/document.rb +643 -0
- data/lib/Pdf/extractor.rb +139 -0
- data/lib/Pdf/text_editor.rb +231 -0
- data/lib/Slides/converter.rb +105 -0
- data/lib/Slides/document.rb +489 -0
- data/lib/Slides/extractor.rb +208 -0
- data/lib/Storage/folder.rb +227 -0
- data/lib/Words/builder.rb +159 -0
- data/lib/Words/converter.rb +79 -0
- data/lib/Words/document.rb +295 -0
- data/lib/Words/extractor.rb +318 -0
- data/lib/Words/mail_merge.rb +143 -0
- data/lib/aspose_barcode.rb +4 -0
- data/lib/aspose_cells.rb +7 -0
- data/lib/aspose_common.rb +12 -0
- data/lib/aspose_ocr.rb +4 -0
- data/lib/aspose_pdf.rb +6 -0
- data/lib/aspose_slides.rb +4 -0
- data/lib/aspose_storage.rb +2 -0
- data/lib/aspose_words.rb +6 -0
- data/lib/asposecloudsdk.rb +10 -0
- data/lib/asposecloudsdk/version.rb +3 -0
- metadata +145 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
# This class allows you to set the AppSID and AppKey values you get upon signing up
|
2
|
+
module Aspose
|
3
|
+
module Cloud
|
4
|
+
module Common
|
5
|
+
class AsposeApp
|
6
|
+
def initialize(app_sid,app_key)
|
7
|
+
$app_sid = app_sid
|
8
|
+
$app_key = app_key
|
9
|
+
$out_put_location = ''
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# This class allows you to set the base host Aspose URI
|
2
|
+
module Aspose
|
3
|
+
module Cloud
|
4
|
+
module Common
|
5
|
+
class Product
|
6
|
+
def initialize
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
# Sets the host product URI
|
11
|
+
def self.set_base_product_uri product_uri
|
12
|
+
$product_uri = product_uri
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/Common/utils.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# This class provides common methods to be repeatedly used by other wrapper classes
|
2
|
+
module Aspose
|
3
|
+
module Cloud
|
4
|
+
module Common
|
5
|
+
class Utils
|
6
|
+
# Signs a URI with your appSID and Key.
|
7
|
+
# * :url describes the URL to sign
|
8
|
+
|
9
|
+
def self.sign(url)
|
10
|
+
url = URI.escape(url)
|
11
|
+
parsed_url = URI.parse(url)
|
12
|
+
|
13
|
+
url_to_sign =''
|
14
|
+
if parsed_url.query.nil?
|
15
|
+
url_to_sign = parsed_url.scheme+'://' + parsed_url.host + parsed_url.path + '?appSID=' + $app_sid
|
16
|
+
else
|
17
|
+
url_to_sign = parsed_url.scheme+'://' + parsed_url.host + parsed_url.path + '?' + parsed_url.query + '&appSID=' + $app_sid
|
18
|
+
end
|
19
|
+
|
20
|
+
# create a signature using the private key and the URL
|
21
|
+
raw_signature = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), $app_key, url_to_sign)
|
22
|
+
|
23
|
+
#Convert raw to encoded string
|
24
|
+
signature = Base64.strict_encode64(raw_signature).tr('+/','-_')
|
25
|
+
|
26
|
+
#remove invalid character
|
27
|
+
signature = signature.gsub(/[=_-]/,'=' => '','_' => '%2f','-' => '%2b')
|
28
|
+
|
29
|
+
#Define expression
|
30
|
+
pat = Regexp.new('%[0-9a-f]{2}')
|
31
|
+
|
32
|
+
#Replace the portion matched to the above pattern to upper case
|
33
|
+
for i in 0..5
|
34
|
+
signature = signature.sub(pat,pat.match(signature).to_s.upcase)
|
35
|
+
end
|
36
|
+
|
37
|
+
# prepend the server and append the signature.
|
38
|
+
signed_url = url_to_sign + "&signature=#{signature}"
|
39
|
+
return signed_url
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.validate_output(result)
|
43
|
+
|
44
|
+
validate = ['Unknown file format.', 'Unable to read beyond the end of the stream',
|
45
|
+
'Index was out of range', 'Cannot read that as a ZipFile', 'Not a Microsoft PowerPoint 2007 presentation',
|
46
|
+
'Index was outside the bounds of the array', 'An attempt was made to move the position before the beginning of the stream',
|
47
|
+
]
|
48
|
+
|
49
|
+
invalid = false
|
50
|
+
|
51
|
+
validate.each do |value|
|
52
|
+
if result.index(value) != nil
|
53
|
+
invalid = ture
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
if invalid == true
|
58
|
+
return result
|
59
|
+
else
|
60
|
+
return ''
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Parses JSON date value to a valid date format
|
65
|
+
# * :datestring holds the JSON Date value
|
66
|
+
def self.parse_date(date_string)
|
67
|
+
seconds_since_epoch = date_string.scan(/[0-9]+/)[0].to_i
|
68
|
+
return Time.at((seconds_since_epoch-(21600000 + 18000000))/1000)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Uploads a binary file from the client system
|
72
|
+
# * :localfile holds the local file path along with name
|
73
|
+
# * :url holds the required url to use while uploading the file to Aspose Storage
|
74
|
+
def self.upload_file_binary(localfile,url)
|
75
|
+
RestClient.put( url,File.new(localfile, 'rb'))
|
76
|
+
end
|
77
|
+
|
78
|
+
# Gets the count of a particular field in the response
|
79
|
+
# * :localfile holds the local file path along with name
|
80
|
+
# * :url holds the required url to use while uploading the file to Aspose Storage
|
81
|
+
def self.get_field_count(url,field_name)
|
82
|
+
response = RestClient.get(url, :accept => 'application/xml')
|
83
|
+
doc = REXML::Document.new(response.body)
|
84
|
+
pages = []
|
85
|
+
doc.elements.each(field_name) do |ele|
|
86
|
+
pages << ele.text
|
87
|
+
end
|
88
|
+
return pages.size
|
89
|
+
end
|
90
|
+
# Saves the response stream to a local file.
|
91
|
+
def self.save_file(response_stream,local_file)
|
92
|
+
open(local_file, 'wb') do |file|
|
93
|
+
file.write(response_stream.body)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.get_filename(file)
|
98
|
+
|
99
|
+
filename = File.basename(file, File.extname(file) );
|
100
|
+
|
101
|
+
return filename
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module Aspose
|
2
|
+
module Cloud
|
3
|
+
|
4
|
+
module OCR
|
5
|
+
class Extractor
|
6
|
+
def initialize
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
def extract_text(*args)
|
11
|
+
case args.size
|
12
|
+
when 2
|
13
|
+
image_file_name,folder = *args
|
14
|
+
begin
|
15
|
+
str_uri = ''
|
16
|
+
if(folder=='' || folder==nil)
|
17
|
+
str_uri += $product_uri + '/ocr/' + image_file_name.to_s + '/recognize'
|
18
|
+
else
|
19
|
+
str_uri += $product_uri + '/ocr/' + image_file_name.to_s + '/recognize?folder=' + folder.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
23
|
+
|
24
|
+
response = RestClient.get(signed_uri, :accept=> 'application/json')
|
25
|
+
json = JSON.parse(response)
|
26
|
+
return json
|
27
|
+
rescue Exception=>e
|
28
|
+
print e
|
29
|
+
return nil
|
30
|
+
end
|
31
|
+
when 4
|
32
|
+
image_file_name,folder,language,use_default_dictionaries = *args
|
33
|
+
begin
|
34
|
+
str_uri = ''
|
35
|
+
if(folder=='' || folder==nil)
|
36
|
+
str_uri += $product_uri + '/ocr/' + image_file_name.to_s + '/recognize?language=' + language.to_s + '&useDefaultDictionaries=' + use_default_dictionaries.to_s
|
37
|
+
else
|
38
|
+
str_uri += $product_uri + '/ocr/' + image_file_name.to_s + '/recognize?language=' + language.to_s + '&useDefaultDictionaries=' + use_default_dictionaries.to_s + '&folder=' + folder.to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
42
|
+
|
43
|
+
response = RestClient.get(signed_uri, :accept=> 'application/json')
|
44
|
+
json = JSON.parse(response)
|
45
|
+
return json
|
46
|
+
rescue Exception=>e
|
47
|
+
print e
|
48
|
+
return nil
|
49
|
+
end
|
50
|
+
when 1
|
51
|
+
image_file_name = args[0]
|
52
|
+
begin
|
53
|
+
str_uri = $product_uri + '/ocr/' + image_file_name + '/recognize?useDefaultDictionaries=true'
|
54
|
+
signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
55
|
+
response = RestClient.get(signed_uri, :accept=> 'application/json')
|
56
|
+
json = JSON.parse(response)
|
57
|
+
return json
|
58
|
+
rescue Exception=>e
|
59
|
+
print e
|
60
|
+
return nil
|
61
|
+
end
|
62
|
+
when 8
|
63
|
+
image_file_name, language , use_default_dictionaries, x , y, height, width, folder = *args
|
64
|
+
begin
|
65
|
+
str_uri = $product_uri
|
66
|
+
str_uri += '/ocr/'
|
67
|
+
str_uri += image_file_name
|
68
|
+
str_uri += '/recognize?language='
|
69
|
+
str_uri += language
|
70
|
+
str_uri += ((x >= 0 && y >= 0 && width > 0 && height > 0) ? '&rectX=' + x.to_s + '&rectY=' + y.to_s + '&rectWidth=' + width.to_s + '&rectHeight=' + height.to_s : '')
|
71
|
+
str_uri += '&useDefaultDictionaries='
|
72
|
+
str_uri += ((use_default_dictionaries) ? 'true' : 'false')
|
73
|
+
str_uri +=((folder=='') ? '' : '&folder=' + folder)
|
74
|
+
|
75
|
+
signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
76
|
+
|
77
|
+
response = RestClient.get(signed_uri, :accept=> 'application/json')
|
78
|
+
json = JSON.parse(response)
|
79
|
+
return json
|
80
|
+
rescue Exception=>e
|
81
|
+
print e
|
82
|
+
return nil
|
83
|
+
end
|
84
|
+
when 3
|
85
|
+
stream,language,use_default_dictionaries = *args
|
86
|
+
begin
|
87
|
+
str_uri = $product_uri + '/ocr/recognize?language=' + language.to_s + '&useDefaultDictionaries=' + use_default_dictionaries.to_s
|
88
|
+
signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
89
|
+
response = RestClient.post(signed_uri,stream, :accept=> 'application/json')
|
90
|
+
json = JSON.parse(response)
|
91
|
+
return json
|
92
|
+
rescue Exception=>e
|
93
|
+
print e
|
94
|
+
return nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def extract_text_from_local_file(local_file,language,use_default_dictionaries)
|
101
|
+
begin
|
102
|
+
str_uri = $product_uri + '/ocr/recognize?language=' + language.to_s + '&useDefaultDictionaries=' + use_default_dictionaries.to_s
|
103
|
+
file_stream = File.binread(local_file)
|
104
|
+
signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
105
|
+
response = RestClient.post(signed_uri,file_stream, :accept=> 'application/json')
|
106
|
+
json = JSON.parse(response)
|
107
|
+
return json
|
108
|
+
rescue Exception=>e
|
109
|
+
print e
|
110
|
+
return nil
|
111
|
+
end
|
112
|
+
end
|
113
|
+
def extract_text_from_url(url,language,use_default_dictionaries)
|
114
|
+
begin
|
115
|
+
str_uri = $product_uri + '/ocr/recognize?url=' + url + '&language=' + language + '&useDefaultDictionaries=' + use_default_dictionaries
|
116
|
+
signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
117
|
+
response = RestClient.post(signed_uri,:accept => 'application/json')
|
118
|
+
json=JSON.parse(response)
|
119
|
+
return json
|
120
|
+
rescue Exception=>e
|
121
|
+
print e
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,533 @@
|
|
1
|
+
module Aspose
|
2
|
+
module Cloud
|
3
|
+
|
4
|
+
module Pdf
|
5
|
+
class AnnotationEditor
|
6
|
+
def initialize filename
|
7
|
+
@filename = filename
|
8
|
+
end
|
9
|
+
|
10
|
+
=begin
|
11
|
+
Gets number of annotations on a specified document page
|
12
|
+
@param number page_number
|
13
|
+
=end
|
14
|
+
|
15
|
+
def get_annotations_count page_number
|
16
|
+
begin
|
17
|
+
|
18
|
+
if @filename == ''
|
19
|
+
raise 'filename not specified'
|
20
|
+
end
|
21
|
+
|
22
|
+
if page_number == ''
|
23
|
+
raise 'page number not specified'
|
24
|
+
end
|
25
|
+
|
26
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s + '/annotations'
|
27
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
28
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
29
|
+
|
30
|
+
stream_hash = JSON.parse(response_stream)
|
31
|
+
|
32
|
+
return stream_hash['Annotations']['List'].length
|
33
|
+
|
34
|
+
|
35
|
+
rescue Exception=>e
|
36
|
+
print e
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
=begin
|
41
|
+
Gets a specfied annotation on a specified document page
|
42
|
+
@param number page_number
|
43
|
+
@param number annotation_index
|
44
|
+
=end
|
45
|
+
|
46
|
+
def get_annotation page_number, annotation_index
|
47
|
+
begin
|
48
|
+
|
49
|
+
if @filename == ''
|
50
|
+
raise 'filename not specified'
|
51
|
+
end
|
52
|
+
|
53
|
+
if page_number == ''
|
54
|
+
raise 'page number not specified'
|
55
|
+
end
|
56
|
+
|
57
|
+
if annotation_index == ''
|
58
|
+
raise 'annotation index not specified'
|
59
|
+
end
|
60
|
+
|
61
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s + '/annotations/' + annotation_index.to_s
|
62
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
63
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
64
|
+
|
65
|
+
stream_hash = JSON.parse(response_stream)
|
66
|
+
|
67
|
+
return stream_hash['Annotation']
|
68
|
+
|
69
|
+
|
70
|
+
rescue Exception=>e
|
71
|
+
print e
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
=begin
|
76
|
+
Gets list of all the annotations on a specified document page
|
77
|
+
@param number page_number
|
78
|
+
=end
|
79
|
+
|
80
|
+
def get_all_annotation page_number
|
81
|
+
begin
|
82
|
+
|
83
|
+
if @filename == ''
|
84
|
+
raise 'filename not specified'
|
85
|
+
end
|
86
|
+
|
87
|
+
if page_number == ''
|
88
|
+
raise 'page number not specified'
|
89
|
+
end
|
90
|
+
|
91
|
+
total_annotations = self.get_annotations_count(page_number)
|
92
|
+
|
93
|
+
all_annotations = Array.new
|
94
|
+
|
95
|
+
index = 1
|
96
|
+
while index <= total_annotations
|
97
|
+
|
98
|
+
all_annotations.push(self.get_annotation(page_number, index))
|
99
|
+
|
100
|
+
index+=1
|
101
|
+
end
|
102
|
+
|
103
|
+
return all_annotations
|
104
|
+
|
105
|
+
|
106
|
+
rescue Exception=>e
|
107
|
+
print e
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
=begin
|
112
|
+
Gets total number of Bookmarks in a Pdf document
|
113
|
+
=end
|
114
|
+
|
115
|
+
def get_bookmarks_count
|
116
|
+
begin
|
117
|
+
|
118
|
+
if @filename == ''
|
119
|
+
raise 'filename not specified'
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/bookmarks'
|
124
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
125
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
126
|
+
|
127
|
+
stream_hash = JSON.parse(response_stream)
|
128
|
+
|
129
|
+
return stream_hash['Bookmarks']['List'].length
|
130
|
+
|
131
|
+
|
132
|
+
rescue Exception=>e
|
133
|
+
print e
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
=begin
|
138
|
+
Gets number of child bookmarks in a specfied parent bookmark
|
139
|
+
@param number parent
|
140
|
+
=end
|
141
|
+
|
142
|
+
def get_child_bookmarks_count parent
|
143
|
+
begin
|
144
|
+
|
145
|
+
if @filename == ''
|
146
|
+
raise 'filename not specified'
|
147
|
+
end
|
148
|
+
|
149
|
+
if parent == ''
|
150
|
+
raise 'parent not specified'
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/bookmarks/' + parent.to_s + '/bookmarks'
|
155
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
156
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
157
|
+
|
158
|
+
stream_hash = JSON.parse(response_stream)
|
159
|
+
|
160
|
+
return stream_hash['Bookmarks']['List'].length
|
161
|
+
|
162
|
+
|
163
|
+
rescue Exception=>e
|
164
|
+
print e
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
=begin
|
169
|
+
Gets a specfied Bookmark from a PDF document
|
170
|
+
@param number bookmark_index
|
171
|
+
=end
|
172
|
+
|
173
|
+
def get_bookmark bookmark_index
|
174
|
+
begin
|
175
|
+
|
176
|
+
if @filename == ''
|
177
|
+
raise 'filename not specified'
|
178
|
+
end
|
179
|
+
|
180
|
+
if bookmark_index == ''
|
181
|
+
raise 'bookmark index not specified'
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/bookmarks/' + bookmark_index.to_s
|
186
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
187
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
188
|
+
|
189
|
+
stream_hash = JSON.parse(response_stream)
|
190
|
+
|
191
|
+
return stream_hash['Bookmark']
|
192
|
+
|
193
|
+
|
194
|
+
rescue Exception=>e
|
195
|
+
print e
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
=begin
|
200
|
+
Gets a specfied Child Bookmark from a PDF document
|
201
|
+
@param number parent_index
|
202
|
+
@param number child_index
|
203
|
+
=end
|
204
|
+
|
205
|
+
def get_child_bookmark parent_index, child_index
|
206
|
+
begin
|
207
|
+
|
208
|
+
if @filename == ''
|
209
|
+
raise 'filename not specified'
|
210
|
+
end
|
211
|
+
|
212
|
+
if parent_index == ''
|
213
|
+
raise 'parent index not specified'
|
214
|
+
end
|
215
|
+
|
216
|
+
if child_index == ''
|
217
|
+
raise 'child index not specified'
|
218
|
+
end
|
219
|
+
|
220
|
+
|
221
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/bookmarks/' + parent_index.to_s + '/bookmarks/' + child_index.to_s
|
222
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
223
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
224
|
+
|
225
|
+
stream_hash = JSON.parse(response_stream)
|
226
|
+
|
227
|
+
return stream_hash['Bookmark']
|
228
|
+
|
229
|
+
|
230
|
+
rescue Exception=>e
|
231
|
+
print e
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
=begin
|
236
|
+
Gets list of all the bookmarks in pdf
|
237
|
+
=end
|
238
|
+
|
239
|
+
def get_all_bookmarks
|
240
|
+
begin
|
241
|
+
|
242
|
+
if @filename == ''
|
243
|
+
raise 'filename not specified'
|
244
|
+
end
|
245
|
+
|
246
|
+
|
247
|
+
total_bookmarks = self.get_bookmarks_count
|
248
|
+
|
249
|
+
all_bookmarks = Array.new
|
250
|
+
|
251
|
+
index = 1
|
252
|
+
while index <= total_bookmarks
|
253
|
+
|
254
|
+
all_annotations.push(self.get_bookmark(index))
|
255
|
+
|
256
|
+
index+=1
|
257
|
+
end
|
258
|
+
|
259
|
+
return all_bookmarks
|
260
|
+
|
261
|
+
|
262
|
+
rescue Exception=>e
|
263
|
+
print e
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
=begin
|
268
|
+
Gets total number of Attachments in a Pdf document
|
269
|
+
=end
|
270
|
+
|
271
|
+
def get_attachments_count
|
272
|
+
begin
|
273
|
+
|
274
|
+
if @filename == ''
|
275
|
+
raise 'filename not specified'
|
276
|
+
end
|
277
|
+
|
278
|
+
|
279
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/attachments'
|
280
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
281
|
+
|
282
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
283
|
+
|
284
|
+
stream_hash = JSON.parse(response_stream)
|
285
|
+
|
286
|
+
return stream_hash['Attachments']['List'].length
|
287
|
+
|
288
|
+
|
289
|
+
rescue Exception=>e
|
290
|
+
print e
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
=begin
|
295
|
+
Gets a specfied Attachment from a PDF document
|
296
|
+
@param number attachment_index
|
297
|
+
=end
|
298
|
+
|
299
|
+
def get_attachment attachment_index
|
300
|
+
begin
|
301
|
+
|
302
|
+
if @filename == ''
|
303
|
+
raise 'filename not specified'
|
304
|
+
end
|
305
|
+
|
306
|
+
if attachment_index == ''
|
307
|
+
raise 'attachment index not specified'
|
308
|
+
end
|
309
|
+
|
310
|
+
|
311
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/attachments/' + attachment_index.to_s
|
312
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
313
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
314
|
+
|
315
|
+
stream_hash = JSON.parse(response_stream)
|
316
|
+
|
317
|
+
return stream_hash['Attachment']
|
318
|
+
|
319
|
+
|
320
|
+
rescue Exception=>e
|
321
|
+
print e
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
=begin
|
326
|
+
Gets list of all the attachments in pdf
|
327
|
+
=end
|
328
|
+
|
329
|
+
def get_all_attachments
|
330
|
+
begin
|
331
|
+
|
332
|
+
if @filename == ''
|
333
|
+
raise 'filename not specified'
|
334
|
+
end
|
335
|
+
|
336
|
+
|
337
|
+
total_attachments = self.get_attachments_count
|
338
|
+
|
339
|
+
all_attachments = Array.new
|
340
|
+
|
341
|
+
index = 1
|
342
|
+
while index <= total_attachments
|
343
|
+
|
344
|
+
all_annotations.push(self.get_attachment(index))
|
345
|
+
|
346
|
+
index+=1
|
347
|
+
end
|
348
|
+
|
349
|
+
return all_attachments
|
350
|
+
|
351
|
+
|
352
|
+
rescue Exception=>e
|
353
|
+
print e
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
=begin
|
358
|
+
Download a specfied Attachment from a PDF document
|
359
|
+
@param number attachment_index
|
360
|
+
=end
|
361
|
+
|
362
|
+
def download_attachment attachment_index
|
363
|
+
begin
|
364
|
+
|
365
|
+
if @filename == ''
|
366
|
+
raise 'filename not specified'
|
367
|
+
end
|
368
|
+
|
369
|
+
if attachment_index == ''
|
370
|
+
raise 'attachment index not specified'
|
371
|
+
end
|
372
|
+
|
373
|
+
file_info = self.get_attachment(attachment_index)
|
374
|
+
|
375
|
+
|
376
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/attachments/' + attachment_index.to_s + '/download'
|
377
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
378
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
379
|
+
|
380
|
+
valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
|
381
|
+
|
382
|
+
if valid_output == ''
|
383
|
+
output_path = $out_put_location + file_info['Name'];
|
384
|
+
Aspose::Cloud::Common::Utils.saveFile(response_stream,output_path)
|
385
|
+
return ''
|
386
|
+
else
|
387
|
+
return valid_output
|
388
|
+
end
|
389
|
+
|
390
|
+
|
391
|
+
rescue Exception=>e
|
392
|
+
print e
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
=begin
|
397
|
+
Gets total number of Links in a Pdf document
|
398
|
+
@param number page_number
|
399
|
+
=end
|
400
|
+
|
401
|
+
def get_links_count page_number
|
402
|
+
begin
|
403
|
+
|
404
|
+
if @filename == ''
|
405
|
+
raise 'filename not specified'
|
406
|
+
end
|
407
|
+
|
408
|
+
if page_number == ''
|
409
|
+
raise 'page number not specified'
|
410
|
+
end
|
411
|
+
|
412
|
+
|
413
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s + '/links'
|
414
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
415
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
416
|
+
|
417
|
+
stream_hash = JSON.parse(response_stream)
|
418
|
+
|
419
|
+
return stream_hash['Links']['List'].length
|
420
|
+
|
421
|
+
|
422
|
+
rescue Exception=>e
|
423
|
+
print e
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
=begin
|
428
|
+
Gets a specfied link on a specified document page
|
429
|
+
@param number page_number
|
430
|
+
@param number annotation_index
|
431
|
+
=end
|
432
|
+
|
433
|
+
def get_link page_number, link_index
|
434
|
+
begin
|
435
|
+
|
436
|
+
if @filename == ''
|
437
|
+
raise 'filename not specified'
|
438
|
+
end
|
439
|
+
|
440
|
+
if page_number == ''
|
441
|
+
raise 'page number not specified'
|
442
|
+
end
|
443
|
+
|
444
|
+
if link_index == ''
|
445
|
+
raise 'link index not specified'
|
446
|
+
end
|
447
|
+
|
448
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s + '/links/' + link_index.to_s
|
449
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
450
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
451
|
+
|
452
|
+
stream_hash = JSON.parse(response_stream)
|
453
|
+
|
454
|
+
return stream_hash['Link']
|
455
|
+
|
456
|
+
|
457
|
+
rescue Exception=>e
|
458
|
+
print e
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
462
|
+
=begin
|
463
|
+
Gets list of all the links on a specified document page
|
464
|
+
@param number page_number
|
465
|
+
=end
|
466
|
+
|
467
|
+
def get_all_links page_number
|
468
|
+
begin
|
469
|
+
|
470
|
+
if @filename == ''
|
471
|
+
raise 'filename not specified'
|
472
|
+
end
|
473
|
+
|
474
|
+
if page_number == ''
|
475
|
+
raise 'page number not specified'
|
476
|
+
end
|
477
|
+
|
478
|
+
total_links = self.get_links_count(page_number)
|
479
|
+
|
480
|
+
all_links = Array.new
|
481
|
+
|
482
|
+
index = 1
|
483
|
+
while index <= total_links
|
484
|
+
|
485
|
+
all_annotations.push(self.get_link(page_number, index))
|
486
|
+
|
487
|
+
index+=1
|
488
|
+
end
|
489
|
+
|
490
|
+
return all_links
|
491
|
+
|
492
|
+
|
493
|
+
rescue Exception=>e
|
494
|
+
print e
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
=begin
|
499
|
+
Checks whether selected bookmark is parent or child Gets a specfied child Bookmark for selected parent bookmark in Pdf document
|
500
|
+
@param number bookmark_index
|
501
|
+
=end
|
502
|
+
|
503
|
+
def is_child_bookmark bookmark_index
|
504
|
+
begin
|
505
|
+
|
506
|
+
if @filename == ''
|
507
|
+
raise 'filename not specified'
|
508
|
+
end
|
509
|
+
|
510
|
+
if bookmark_index == ''
|
511
|
+
raise 'bookmark index not specified'
|
512
|
+
end
|
513
|
+
|
514
|
+
|
515
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/bookmarks/' + bookmark_index.to_s
|
516
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
517
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
518
|
+
|
519
|
+
stream_hash = JSON.parse(response_stream)
|
520
|
+
|
521
|
+
return stream_hash['Bookmark']
|
522
|
+
|
523
|
+
|
524
|
+
rescue Exception=>e
|
525
|
+
print e
|
526
|
+
end
|
527
|
+
end
|
528
|
+
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
end
|
533
|
+
end
|