asposecloudsdk 0.0.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.
- 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,201 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
module Aspose
|
4
|
+
module Cloud
|
5
|
+
module Pdf
|
6
|
+
#converts pages or document into different formats
|
7
|
+
class Converter
|
8
|
+
def initialize(filename)
|
9
|
+
@filename = filename
|
10
|
+
@save_format = 'pdf'
|
11
|
+
end
|
12
|
+
|
13
|
+
# convert a particular page to image with specified size
|
14
|
+
# @param string page_number
|
15
|
+
# @param string image_format
|
16
|
+
# @param number width
|
17
|
+
# @param number height
|
18
|
+
|
19
|
+
def convert_to_image_by_size(page_number, image_format, width=0, height=0)
|
20
|
+
|
21
|
+
begin
|
22
|
+
|
23
|
+
if @filename == ''
|
24
|
+
raise('filename not specified')
|
25
|
+
end
|
26
|
+
|
27
|
+
if page_number == ''
|
28
|
+
raise('page number not specified')
|
29
|
+
end
|
30
|
+
|
31
|
+
if image_format == ''
|
32
|
+
raise('image format not specified')
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s + '?format=' + image_format + '&width=' + width.to_s + '&height=' + height.to_s
|
37
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
38
|
+
|
39
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
40
|
+
|
41
|
+
valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
|
42
|
+
|
43
|
+
if valid_output == ''
|
44
|
+
output_path = $out_put_location + Aspose::Cloud::Common::Utils.get_filename(@filename) + '_' + page_number.to_s + '.' + image_format
|
45
|
+
Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
|
46
|
+
return ''
|
47
|
+
else
|
48
|
+
return valid_output
|
49
|
+
end
|
50
|
+
|
51
|
+
rescue Exception=>e
|
52
|
+
print e
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
=begin
|
58
|
+
convert a particular page to image with default size
|
59
|
+
@param number page_number
|
60
|
+
@param string image_format
|
61
|
+
=end
|
62
|
+
|
63
|
+
def convert_to_image page_number, image_format
|
64
|
+
begin
|
65
|
+
|
66
|
+
if page_number == ''
|
67
|
+
raise('page number not specified')
|
68
|
+
end
|
69
|
+
|
70
|
+
if image_format == ''
|
71
|
+
raise 'image format not specified'
|
72
|
+
end
|
73
|
+
|
74
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s + '?format=' + image_format
|
75
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
76
|
+
|
77
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
78
|
+
|
79
|
+
valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
|
80
|
+
|
81
|
+
if valid_output == ''
|
82
|
+
output_path = $out_put_location + Aspose::Cloud::Common::Utils.get_filename(@filename) + '_' + page_number.to_s + '.' + image_format
|
83
|
+
Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
|
84
|
+
return ''
|
85
|
+
else
|
86
|
+
return valid_output
|
87
|
+
end
|
88
|
+
|
89
|
+
rescue Exception=>e
|
90
|
+
print e
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
=begin
|
95
|
+
convert a document to SaveFormat
|
96
|
+
=end
|
97
|
+
|
98
|
+
def convert storage_name='', folder='', save_format=''
|
99
|
+
begin
|
100
|
+
|
101
|
+
if save_format.empty? == false
|
102
|
+
@save_format = save_format
|
103
|
+
end
|
104
|
+
|
105
|
+
if @save_format == ''
|
106
|
+
raise('save format not specified')
|
107
|
+
end
|
108
|
+
if(storage_name.empty? == true)
|
109
|
+
str_uri = $product_uri + '/pdf/' + @filename + '?format=' + @save_format
|
110
|
+
else
|
111
|
+
str_uri = $product_uri + '/pdf/' + @filename + '?&format=' + @save_format + '&storage='+@save_format+'&folder='+folder
|
112
|
+
end
|
113
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
114
|
+
|
115
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
116
|
+
|
117
|
+
valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
|
118
|
+
|
119
|
+
if valid_output == ''
|
120
|
+
|
121
|
+
if @save_format == 'html'
|
122
|
+
save_format = 'zip'
|
123
|
+
else
|
124
|
+
save_format = @save_format
|
125
|
+
end
|
126
|
+
|
127
|
+
output_path = $out_put_location + Aspose::Cloud::Common::Utils.get_filename(@filename) + '.' + save_format
|
128
|
+
Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
|
129
|
+
return output_path
|
130
|
+
else
|
131
|
+
return valid_output
|
132
|
+
end
|
133
|
+
|
134
|
+
rescue Exception=>e
|
135
|
+
print e
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
=begin
|
140
|
+
Convert PDF to different file format without using storage
|
141
|
+
@param string inputFile
|
142
|
+
@param string outputFilename
|
143
|
+
@param string outputFormat
|
144
|
+
=end
|
145
|
+
|
146
|
+
def convert_local_file input_file,output_filename,output_format
|
147
|
+
begin
|
148
|
+
|
149
|
+
if input_file == ''
|
150
|
+
raise('input file not specified')
|
151
|
+
end
|
152
|
+
|
153
|
+
if output_filename == ''
|
154
|
+
raise('output file not specified')
|
155
|
+
end
|
156
|
+
|
157
|
+
if output_format == ''
|
158
|
+
raise('output format not specified')
|
159
|
+
end
|
160
|
+
|
161
|
+
if not File.exist?(input_file)
|
162
|
+
raise("input file doesn't exist.")
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
str_uri = $product_uri + '/pdf/convert?format=' + output_format
|
168
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
169
|
+
|
170
|
+
response_stream = Aspose::Cloud::Common::Utils.upload_file_binary(input_file, str_signed_uri)
|
171
|
+
|
172
|
+
valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
|
173
|
+
|
174
|
+
if valid_output == ''
|
175
|
+
|
176
|
+
if output_format == 'html'
|
177
|
+
save_format = 'zip'
|
178
|
+
else
|
179
|
+
save_format = output_format
|
180
|
+
end
|
181
|
+
|
182
|
+
if output_filename == ''
|
183
|
+
output_filename = Utils::get_filename(input_file) + '.' + save_format
|
184
|
+
end
|
185
|
+
|
186
|
+
output_path = $out_put_location + output_filename
|
187
|
+
Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
|
188
|
+
return ''
|
189
|
+
else
|
190
|
+
return valid_output
|
191
|
+
end
|
192
|
+
|
193
|
+
rescue Exception=>e
|
194
|
+
print e
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
data/lib/Pdf/document.rb
ADDED
@@ -0,0 +1,643 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
module Aspose
|
4
|
+
module Cloud
|
5
|
+
|
6
|
+
module Pdf
|
7
|
+
class Document
|
8
|
+
|
9
|
+
def initialize(filename)
|
10
|
+
@filename = filename
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_page_count
|
14
|
+
begin
|
15
|
+
|
16
|
+
if(@filename == '')
|
17
|
+
raise('Filename cannot be empty.')
|
18
|
+
end
|
19
|
+
|
20
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/pages'
|
21
|
+
signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
22
|
+
|
23
|
+
response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})
|
24
|
+
|
25
|
+
stream_hash = JSON.parse(response_stream)
|
26
|
+
|
27
|
+
return stream_hash['Pages']['List'].count
|
28
|
+
|
29
|
+
rescue Exception=>e
|
30
|
+
print e
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def append_document(base_pdf, new_pdf, startpage = 0, endpage = 0, sourcefolder = '')
|
35
|
+
|
36
|
+
begin
|
37
|
+
|
38
|
+
if base_pdf == ''
|
39
|
+
raise('Base file not specified')
|
40
|
+
end
|
41
|
+
|
42
|
+
if new_pdf == ''
|
43
|
+
raise('File to merge is not specified')
|
44
|
+
end
|
45
|
+
|
46
|
+
if sourcefolder == ''
|
47
|
+
struri = "#{$product_uri}/pdf/#{base_pdf}/appenddocument?appendfile=#{new_pdf}"+(startpage > 0 ? '&startPage=' + startpage : '' ) + (endpage > 0 ? '&endPage=' + endpage : '' )
|
48
|
+
else
|
49
|
+
struri = "#{$product_uri}/pdf/#{base_pdf}/appenddocument?appendfile=#{sourcefolder}/#{new_pdf}"+ (startpage > 0 ? '&startPage=' + startpage : '' ) + (endpage > 0 ? '&endPage=' + endpage : '' )
|
50
|
+
end
|
51
|
+
|
52
|
+
signeduri = Aspose::Cloud::Common::Utils.sign(struri)
|
53
|
+
|
54
|
+
response_stream = RestClient.post signeduri,'', {:accept => 'application/json'}
|
55
|
+
|
56
|
+
|
57
|
+
valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
|
58
|
+
|
59
|
+
if valid_output == ''
|
60
|
+
folder = Aspose::Cloud::AsposeStorage::Folder.new
|
61
|
+
if(sourcefolder == '')
|
62
|
+
output_stream = folder.get_file(base_pdf)
|
63
|
+
else
|
64
|
+
output_stream = folder.get_file(sourcefolder + '/' + base_pdf)
|
65
|
+
end
|
66
|
+
output_path = $out_put_location + base_pdf;
|
67
|
+
|
68
|
+
Aspose::Cloud::Common::Utils.save_file(output_stream,output_path)
|
69
|
+
return ''
|
70
|
+
else
|
71
|
+
return valid_output
|
72
|
+
end
|
73
|
+
|
74
|
+
rescue Exception=>e
|
75
|
+
print e
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
def merge_documents(source_files)
|
81
|
+
begin
|
82
|
+
_mergedfilename = @filename
|
83
|
+
|
84
|
+
# Throw exception if output filename not specified
|
85
|
+
if _mergedfilename == ''
|
86
|
+
raise('Output file not specified')
|
87
|
+
end
|
88
|
+
|
89
|
+
# Throw exception if source files are not provided
|
90
|
+
if source_files.empty? || source_files.length < 2
|
91
|
+
raise('File to merge are not specified')
|
92
|
+
end
|
93
|
+
|
94
|
+
# Build JSON to post
|
95
|
+
json_data = JSON.generate('List'=>source_files)
|
96
|
+
|
97
|
+
struri = "#{$product_uri}/pdf/#{_mergedfilename}/merge"
|
98
|
+
|
99
|
+
signeduri = Aspose::Cloud::Common::Utils.sign(struri)
|
100
|
+
|
101
|
+
responsexml = RestClient.put signeduri, json_data, {:content_type => :json}
|
102
|
+
|
103
|
+
|
104
|
+
xmldoc = REXML::Document.new(responsexml)
|
105
|
+
|
106
|
+
if xmldoc.elements.to_a('SaaSposeResponse/Status').first.text == 'OK'
|
107
|
+
return true
|
108
|
+
else
|
109
|
+
return false
|
110
|
+
end
|
111
|
+
|
112
|
+
rescue Exception=>e
|
113
|
+
print e
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
#Gets the FormField count of the specified PDF document
|
118
|
+
|
119
|
+
def get_form_field_count
|
120
|
+
begin
|
121
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/feilds'
|
122
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
123
|
+
|
124
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
125
|
+
|
126
|
+
stream_hash = JSON.parse(response_stream)
|
127
|
+
|
128
|
+
return stream_hash['Fields']['List'].count
|
129
|
+
|
130
|
+
rescue Exception=>e
|
131
|
+
print e
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
#Gets the list of FormFields from the specified PDF document
|
136
|
+
|
137
|
+
def get_form_fields
|
138
|
+
begin
|
139
|
+
|
140
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/feilds'
|
141
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
142
|
+
|
143
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
144
|
+
|
145
|
+
stream_hash = JSON.parse(response_stream)
|
146
|
+
|
147
|
+
return stream_hash['Fields']['List']
|
148
|
+
|
149
|
+
rescue Exception=>e
|
150
|
+
print e
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# Gets a particular form field
|
155
|
+
# field_name
|
156
|
+
|
157
|
+
def get_form_field(field_name)
|
158
|
+
|
159
|
+
begin
|
160
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/feilds/' + field_name
|
161
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
162
|
+
|
163
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
164
|
+
|
165
|
+
stream_hash = JSON.parse(response_stream)
|
166
|
+
|
167
|
+
return stream_hash['Field']
|
168
|
+
|
169
|
+
rescue Exception=>e
|
170
|
+
print e
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
#Creates a PDF from HTML
|
176
|
+
#@param string $pdfFileName (name of the PDF file to create)
|
177
|
+
#@param string $htmlFileName (name of the HTML template file)
|
178
|
+
|
179
|
+
def create_from_html (pdf_filename, html_filename)
|
180
|
+
|
181
|
+
begin
|
182
|
+
|
183
|
+
if(pdf_filename == '')
|
184
|
+
raise('PDF file name not specified.')
|
185
|
+
end
|
186
|
+
|
187
|
+
if(html_filename == '')
|
188
|
+
raise('HTML file name not specified.')
|
189
|
+
end
|
190
|
+
|
191
|
+
str_uri = $product_uri + '/pdf/' + pdf_filename + '?templatefile=' + html_filename + '&templatetype=html'
|
192
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
193
|
+
|
194
|
+
response_stream = RestClient.put(str_signed_uri, '', {:accept=>'application/json'})
|
195
|
+
|
196
|
+
valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
|
197
|
+
|
198
|
+
if valid_output == ''
|
199
|
+
folder = Aspose::Cloud::AsposeStorage::Folder.new
|
200
|
+
|
201
|
+
output_stream = folder.get_file(pdf_filename)
|
202
|
+
output_path = $out_put_location + pdf_filename;
|
203
|
+
Aspose::Cloud::Common::Utils.save_file(output_stream,output_path)
|
204
|
+
return ''
|
205
|
+
else
|
206
|
+
return valid_output
|
207
|
+
end
|
208
|
+
|
209
|
+
rescue Exception=>e
|
210
|
+
print e
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
#Creates a PDF from XML
|
216
|
+
#@param string $pdfFileName (name of the PDF file to create)
|
217
|
+
#@param string $xsltFileName (name of the XSLT template file)
|
218
|
+
#@param string $xmlFileName (name of the XML file)
|
219
|
+
|
220
|
+
def create_from_xml (pdf_filename, xslt_filename, xml_filename)
|
221
|
+
|
222
|
+
begin
|
223
|
+
|
224
|
+
if(pdf_filename == '')
|
225
|
+
raise('PDF file name not specified.')
|
226
|
+
end
|
227
|
+
|
228
|
+
if(xslt_filename == '')
|
229
|
+
raise('XSLT file name not specified.')
|
230
|
+
end
|
231
|
+
|
232
|
+
if(xml_filename == '')
|
233
|
+
raise('XML file name not specified.')
|
234
|
+
end
|
235
|
+
|
236
|
+
str_uri = $product_uri + '/pdf/' + pdf_filename + '?templatefile=' + xslt_filename + '&datafile=' + xml_filename + '&templatetype=xml'
|
237
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
238
|
+
|
239
|
+
response_stream = RestClient.put(str_signed_uri, '', {:accept=>'application/json'})
|
240
|
+
|
241
|
+
valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
|
242
|
+
|
243
|
+
if valid_output == ''
|
244
|
+
folder = Aspose::Cloud::AsposeStorage::Folder.new
|
245
|
+
|
246
|
+
output_stream = folder.get_file(pdf_filename)
|
247
|
+
output_path = $out_put_location + pdf_filename;
|
248
|
+
Aspose::Cloud::Common::Utils.save_file(output_stream,output_path)
|
249
|
+
return ''
|
250
|
+
else
|
251
|
+
return valid_output
|
252
|
+
end
|
253
|
+
|
254
|
+
rescue Exception=>e
|
255
|
+
print e
|
256
|
+
end
|
257
|
+
|
258
|
+
end
|
259
|
+
|
260
|
+
#Creates an Empty Pdf document
|
261
|
+
#@param string $pdfFileName (name of the PDF file to create)
|
262
|
+
|
263
|
+
def create_empty_pdf (pdf_filename)
|
264
|
+
|
265
|
+
begin
|
266
|
+
|
267
|
+
if(pdf_filename == '')
|
268
|
+
raise('PDF file name not specified.')
|
269
|
+
end
|
270
|
+
|
271
|
+
str_uri = $product_uri + '/pdf/' + pdf_filename
|
272
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
273
|
+
|
274
|
+
response_stream = RestClient.put(str_signed_uri, '', {:accept=>'application/json'})
|
275
|
+
|
276
|
+
valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
|
277
|
+
|
278
|
+
if valid_output == ''
|
279
|
+
folder = Aspose::Cloud::AsposeStorage::Folder.new
|
280
|
+
|
281
|
+
output_stream = folder.get_file(pdf_filename)
|
282
|
+
output_path = $out_put_location + pdf_filename;
|
283
|
+
Aspose::Cloud::Common::Utils.save_file(output_stream,output_path)
|
284
|
+
return ''
|
285
|
+
else
|
286
|
+
return valid_output
|
287
|
+
end
|
288
|
+
|
289
|
+
rescue Exception=>e
|
290
|
+
print e
|
291
|
+
end
|
292
|
+
|
293
|
+
end
|
294
|
+
|
295
|
+
#Add new page to opend pdf file
|
296
|
+
|
297
|
+
def add_new_page
|
298
|
+
|
299
|
+
begin
|
300
|
+
|
301
|
+
if(@filename == '')
|
302
|
+
raise('PDF file name not specified.')
|
303
|
+
end
|
304
|
+
|
305
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/pages'
|
306
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
307
|
+
|
308
|
+
response_stream = RestClient.put(str_signed_uri, '', {:accept=>'application/json'})
|
309
|
+
|
310
|
+
valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
|
311
|
+
|
312
|
+
if valid_output == ''
|
313
|
+
folder = Aspose::Cloud::AsposeStorage::Folder.new
|
314
|
+
|
315
|
+
output_stream = folder.get_file(@filename)
|
316
|
+
output_path = $out_put_location + @filename;
|
317
|
+
Aspose::Cloud::Common::Utils.save_file(output_stream,output_path)
|
318
|
+
return ''
|
319
|
+
else
|
320
|
+
return valid_output
|
321
|
+
end
|
322
|
+
|
323
|
+
rescue Exception=>e
|
324
|
+
print e
|
325
|
+
end
|
326
|
+
|
327
|
+
end
|
328
|
+
|
329
|
+
#Deletes selected page from Pdf document
|
330
|
+
#@param page_number
|
331
|
+
|
332
|
+
def delete_page (page_number)
|
333
|
+
|
334
|
+
begin
|
335
|
+
|
336
|
+
if(@filename == '')
|
337
|
+
raise('PDF file name not specified.')
|
338
|
+
end
|
339
|
+
|
340
|
+
if(page_number == '')
|
341
|
+
raise('page number not specified.')
|
342
|
+
end
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s
|
347
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
348
|
+
|
349
|
+
response_stream = RestClient.delete(str_signed_uri, {:accept=>'application/json'})
|
350
|
+
|
351
|
+
valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
|
352
|
+
|
353
|
+
if valid_output == ''
|
354
|
+
folder = Aspose::Cloud::AsposeStorage::Folder.new
|
355
|
+
|
356
|
+
output_stream = folder.get_file(@filename)
|
357
|
+
output_path = $out_put_location + @filename;
|
358
|
+
Aspose::Cloud::Common::Utils.save_file(output_stream,output_path)
|
359
|
+
return ''
|
360
|
+
else
|
361
|
+
return valid_output
|
362
|
+
end
|
363
|
+
|
364
|
+
rescue Exception=>e
|
365
|
+
print e
|
366
|
+
end
|
367
|
+
|
368
|
+
end
|
369
|
+
|
370
|
+
#Moves selected page in Pdf document to new location
|
371
|
+
#@param page_number
|
372
|
+
#@param new_location
|
373
|
+
|
374
|
+
def move_page (page_number, new_location)
|
375
|
+
|
376
|
+
begin
|
377
|
+
|
378
|
+
if(@filename == '')
|
379
|
+
raise('PDF file name not specified.')
|
380
|
+
end
|
381
|
+
|
382
|
+
if(page_number == '')
|
383
|
+
raise('page number not specified.')
|
384
|
+
end
|
385
|
+
|
386
|
+
if(new_location == '')
|
387
|
+
raise('new location not specified.')
|
388
|
+
end
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s + '/movepage?newindex=' + new_location.to_s
|
393
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
394
|
+
|
395
|
+
response_stream = RestClient.post(str_signed_uri, '', {:accept=>'application/json'})
|
396
|
+
|
397
|
+
valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
|
398
|
+
|
399
|
+
if valid_output == ''
|
400
|
+
folder = Aspose::Cloud::AsposeStorage::Folder.new
|
401
|
+
|
402
|
+
output_stream = folder.get_file(@filename)
|
403
|
+
output_path = $out_put_location + @filename;
|
404
|
+
Aspose::Cloud::Common::Utils.save_file(output_stream,output_path)
|
405
|
+
return ''
|
406
|
+
else
|
407
|
+
return valid_output
|
408
|
+
end
|
409
|
+
|
410
|
+
rescue Exception=>e
|
411
|
+
print e
|
412
|
+
end
|
413
|
+
|
414
|
+
end
|
415
|
+
|
416
|
+
#Replaces Image in PDF File using Local Image Stream
|
417
|
+
#@param page_number
|
418
|
+
#@param image_index
|
419
|
+
#@param image_stream
|
420
|
+
|
421
|
+
def replace_image_stream (page_number, image_index, image_stream)
|
422
|
+
|
423
|
+
begin
|
424
|
+
|
425
|
+
if(@filename == '')
|
426
|
+
raise('PDF file name not specified.')
|
427
|
+
end
|
428
|
+
|
429
|
+
if(page_number == '')
|
430
|
+
raise('page number not specified.')
|
431
|
+
end
|
432
|
+
|
433
|
+
if(image_index == '')
|
434
|
+
raise('image index not specified.')
|
435
|
+
end
|
436
|
+
|
437
|
+
if(image_stream == '')
|
438
|
+
raise('image stream not specified.')
|
439
|
+
end
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s + '/images/' + image_index.to_s
|
444
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
445
|
+
|
446
|
+
response_stream = RestClient.post(str_signed_uri, image_stream, {:accept=>'application/json'})
|
447
|
+
|
448
|
+
valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
|
449
|
+
|
450
|
+
if valid_output == ''
|
451
|
+
folder = Aspose::Cloud::AsposeStorage::Folder.new
|
452
|
+
|
453
|
+
output_stream = folder.get_file(@filename)
|
454
|
+
output_path = $out_put_location + @filename;
|
455
|
+
Aspose::Cloud::Common::Utils.save_file(output_stream,output_path)
|
456
|
+
return ''
|
457
|
+
else
|
458
|
+
return valid_output
|
459
|
+
end
|
460
|
+
|
461
|
+
rescue Exception=>e
|
462
|
+
print e
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
#Replaces Image in PDF File using Local Image Stream
|
467
|
+
#@param page_number
|
468
|
+
#@param image_index
|
469
|
+
#@param image_filename
|
470
|
+
|
471
|
+
def replace_image_file (page_number, image_index, image_filename)
|
472
|
+
|
473
|
+
begin
|
474
|
+
|
475
|
+
if(@filename == '')
|
476
|
+
raise('PDF file name not specified.')
|
477
|
+
end
|
478
|
+
|
479
|
+
if(page_number == '')
|
480
|
+
raise('page number not specified.')
|
481
|
+
end
|
482
|
+
|
483
|
+
if(image_index == '')
|
484
|
+
raise('image index not specified.')
|
485
|
+
end
|
486
|
+
|
487
|
+
if(image_filename == '')
|
488
|
+
raise('image filename not specified.')
|
489
|
+
end
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s + '/images/' + image_index.to_s + '/imagefile=' + image_filename
|
494
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
495
|
+
|
496
|
+
response_stream = RestClient.post(str_signed_uri, '', {:accept=>'application/json'})
|
497
|
+
|
498
|
+
valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
|
499
|
+
|
500
|
+
if valid_output == ''
|
501
|
+
folder = Aspose::Cloud::AsposeStorage::Folder.new
|
502
|
+
|
503
|
+
output_stream = folder.get_file(@filename)
|
504
|
+
output_path = $out_put_location + @filename;
|
505
|
+
Aspose::Cloud::Common::Utils.save_file(output_stream,output_path)
|
506
|
+
return ''
|
507
|
+
else
|
508
|
+
return valid_output
|
509
|
+
end
|
510
|
+
|
511
|
+
rescue Exception=>e
|
512
|
+
print e
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
#Get specified properity of the document
|
517
|
+
#@param string propertyName
|
518
|
+
|
519
|
+
def get_document_property property_name
|
520
|
+
|
521
|
+
begin
|
522
|
+
|
523
|
+
if(@filename == '')
|
524
|
+
raise('PDF file name not specified.')
|
525
|
+
end
|
526
|
+
|
527
|
+
if(property_name == '')
|
528
|
+
raise('property name not specified.')
|
529
|
+
end
|
530
|
+
|
531
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/documentProperties/' + property_name
|
532
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
533
|
+
|
534
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
535
|
+
|
536
|
+
stream_hash = JSON.parse(response_stream)
|
537
|
+
|
538
|
+
return stream_hash['DocumentProperty']
|
539
|
+
|
540
|
+
rescue Exception=>e
|
541
|
+
print e
|
542
|
+
end
|
543
|
+
|
544
|
+
end
|
545
|
+
|
546
|
+
#Get specified properity of the document
|
547
|
+
|
548
|
+
def get_document_properties
|
549
|
+
|
550
|
+
begin
|
551
|
+
|
552
|
+
if(@filename == '')
|
553
|
+
raise('PDF file name not specified.')
|
554
|
+
end
|
555
|
+
|
556
|
+
|
557
|
+
|
558
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/documentProperties'
|
559
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
560
|
+
|
561
|
+
response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'})
|
562
|
+
|
563
|
+
stream_hash = JSON.parse(response_stream)
|
564
|
+
return stream_hash['DocumentProperties']['List']
|
565
|
+
|
566
|
+
rescue Exception=>e
|
567
|
+
print e
|
568
|
+
end
|
569
|
+
|
570
|
+
end
|
571
|
+
|
572
|
+
#Set specified properity of the document
|
573
|
+
#@param string propertyName
|
574
|
+
#@param string propertyValue
|
575
|
+
|
576
|
+
def set_document_property property_name, property_value
|
577
|
+
|
578
|
+
begin
|
579
|
+
|
580
|
+
if(@filename == '')
|
581
|
+
raise('PDF file name not specified.')
|
582
|
+
end
|
583
|
+
|
584
|
+
if(property_name == '')
|
585
|
+
raise('property name not specified.')
|
586
|
+
end
|
587
|
+
|
588
|
+
if(property_value == '')
|
589
|
+
raise('property value not specified.')
|
590
|
+
end
|
591
|
+
|
592
|
+
# Build JSON to post
|
593
|
+
json_data = JSON.generate('Value'=>property_value)
|
594
|
+
|
595
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/documentProperties/' + property_name
|
596
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
597
|
+
|
598
|
+
response_stream = RestClient.put(str_signed_uri, json_data, {:accept=>'application/json'})
|
599
|
+
|
600
|
+
stream_hash = JSON.parse(response_stream)
|
601
|
+
|
602
|
+
return stream_hash['DocumentProperty']
|
603
|
+
|
604
|
+
rescue Exception=>e
|
605
|
+
print e
|
606
|
+
end
|
607
|
+
|
608
|
+
end
|
609
|
+
|
610
|
+
#Remove All properties of a document
|
611
|
+
|
612
|
+
def remove_all_properties
|
613
|
+
|
614
|
+
begin
|
615
|
+
|
616
|
+
if(@filename == '')
|
617
|
+
raise('PDF file name not specified.')
|
618
|
+
end
|
619
|
+
|
620
|
+
str_uri = $product_uri + '/pdf/' + @filename + '/documentProperties/'
|
621
|
+
str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
|
622
|
+
|
623
|
+
response_stream = RestClient.delete(str_signed_uri, {:accept=>'application/json'})
|
624
|
+
|
625
|
+
stream_hash = JSON.parse(response_stream)
|
626
|
+
|
627
|
+
if stream_hash['Code'] == 200
|
628
|
+
return true;
|
629
|
+
else
|
630
|
+
return false;
|
631
|
+
end
|
632
|
+
|
633
|
+
rescue Exception=>e
|
634
|
+
print e
|
635
|
+
end
|
636
|
+
|
637
|
+
end
|
638
|
+
|
639
|
+
end
|
640
|
+
end
|
641
|
+
|
642
|
+
end
|
643
|
+
end
|