Class: Aspose::Cloud::Words::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/Words/extractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Extractor

Returns a new instance of Extractor.



7
8
9
# File 'lib/Words/extractor.rb', line 7

def initialize filename
  @filename = filename
end

Instance Method Details

#convert_drawing_object(index, render_format) ⇒ Object

Convert drawing object to image

@param number index
@param string render_format


135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/Words/extractor.rb', line 135

def convert_drawing_object index, render_format
      
  begin

    if @filename == ''
      raise 'Base file not specified.'
    end

    if index == ''
      raise 'Index not specified.'
    end

    if render_format == ''
      raise 'Render Format not specified.'
    end

    str_uri = $product_uri + '/words/' + @filename + '/drawingObjects/' + index.to_s + '/imagedata'
    signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)

    response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})

    valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)

    if valid_output == ''                    
  
      output_path = $out_put_location + Aspose::Cloud::Common::Utils.get_filename(@filename) + '_' + index.to_s + '.' + render_format
      Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
      return output_path
    else
      return valid_output
    end

  rescue Exception=>e
    print e
  end
      
end

#get_drawing_object(object_uri, output_path) ⇒ Object

Get the drawing object from document

@param string object_uri
@param string output_path


210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/Words/extractor.rb', line 210

def get_drawing_object object_uri, output_path
      
  begin

    if @filename == ''
      raise 'Base file not specified.'
    end

    if object_uri == ''
      raise 'Object URI not specified.'
    end

    if output_path == ''
      raise 'Output path not specified.'
    end

    url_arr = object_uri.split('/')
    object_index = url_arr.at(-1)        

    str_uri = object_uri
    signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)

    response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})

    stream_hash = JSON.parse(response_stream)

    if(stream_hash['Code'] == 200)
  
      if stream_hash['DrawingObject']['ImageDataLink'] != ''
        str_uri = str_uri + '/imageData'
        output_path = output_path + '\\DrawingObject_' + object_index.to_s + '.jpeg'
      elsif stream_hash['DrawingObject']['OLEDataLink'] != ''
        str_uri = str_uri + '/oleData'
        output_path = output_path + '\\DrawingObject_' + object_index.to_s + '.xlsx'
      else
        str_uri = str_uri + '?format=jpeg'
        output_path = output_path + '\\DrawingObject_' + object_index.to_s + '.jpeg'
      end
  
      signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
  
      valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)
  
      if valid_output == ''                    

        #            output_path = $out_put_location + Aspose::Cloud::Common::Utils.get_filename(@filename) + '_' + index.to_s + '.' + render_format
        Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
        return output_path
      else
        return valid_output
      end
  
    else
      return false
    end

  rescue Exception=>e
    print e
  end
      
end

#get_drawing_object_listObject

Get the List of drawing object from document



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/Words/extractor.rb', line 177

def get_drawing_object_list
      
  begin

    if @filename == ''
      raise 'Base file not specified.'
    end

    str_uri = $product_uri + '/words/' + @filename + '/drawingObjects'
    signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)

    response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})

    stream_hash = JSON.parse(response_stream)

    if(stream_hash['Code'] == 200)
      return stream_hash['DrawingObjects']['List']
    else
      return false
    end

  rescue Exception=>e
    print e
  end
      
end

#get_drawing_objects(output_path) ⇒ Object

Get the List of drawing object from document

@param string output_path


277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/Words/extractor.rb', line 277

def get_drawing_objects output_path
      
  begin

    if @filename == ''
      raise 'Base file not specified.'
    end

    if output_path == ''
      raise 'Output path not specified.'
    end

    str_uri = $product_uri + '/words/' + @filename + '/drawingObjects'
    signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)

    response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})

    stream_hash = JSON.parse(response_stream)

    if(stream_hash['Code'] == 200)
  
      stream_hash['DrawingObjects']['List'].each { |object| 
  
        self.get_drawing_object(object['link']['Href'], output_path)
    
      }
  
    else
      return false
    end

  rescue Exception=>e
    print e
  end
      
end

#get_image_data(index, render_format) ⇒ Object

Get the Image drawing object from document

@param number index
@param string render_format


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/Words/extractor.rb', line 91

def get_image_data index, render_format
      
  begin

    if @filename == ''
      raise 'Base file not specified.'
    end

    if index == ''
      raise 'Index not specified.'
    end

    if render_format == ''
      raise 'Render Format not specified.'
    end

    str_uri = $product_uri + '/words/' + @filename + '/drawingObjects/' + index.to_s + '/imagedata'
    signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)

    response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})

    valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)

    if valid_output == ''                    
  
      output_path = $out_put_location + Aspose::Cloud::Common::Utils.get_filename(@filename) + '_' + index.to_s + '.' + render_format
      Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
      return output_path
    else
      return valid_output
    end

  rescue Exception=>e
    print e
  end
      
end

#get_ole_data(index, ole_format) ⇒ Object

Get the OLE drawing object from document

@param number index
@param string ole_format


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/Words/extractor.rb', line 48

def get_ole_data index, ole_format
      
  begin

    if @filename == ''
      raise 'Base file not specified.'
    end

    if index == ''
      raise 'Index not specified.'
    end

    if ole_format == ''
      raise 'OLE Format not specified.'
    end

    str_uri = $product_uri + '/words/' + @filename + '/drawingObjects/' + index.to_s + '/oleData'
    signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
    response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})

    valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)

    if valid_output == ''                    
  
      output_path = $out_put_location + Aspose::Cloud::Common::Utils.get_filename(@filename) + '_' + index.to_s + '.' + ole_format
      Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
      return output_path
    else
      return valid_output
    end

  rescue Exception=>e
    print e
  end
      
end

#get_textObject

Gets Text items list from document



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/Words/extractor.rb', line 15

def get_text
      
  begin

    if @filename == ''
      raise 'Base file not specified.'
    end

    str_uri = $product_uri + '/words/' + @filename + '/textItems'
    signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)

    response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'})

    stream_hash = JSON.parse(response_stream)

    if(stream_hash['Code'] == 200)
      return stream_hash['TextItems']['List']
    else
      return false
    end

  rescue Exception=>e
    print e
  end
      
end