Class: Aspose::Cloud::Pdf::Extractor

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

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Extractor

Returns a new instance of Extractor.



5
6
7
8
9
# File 'lib/Pdf/extractor.rb', line 5

def initialize(filename)
  @filename = filename
  raise 'filename not specified.' if filename.empty?
  @base_uri =  Aspose::Cloud::Common::Product.product_uri + '/pdf/' + @filename
end

Instance Method Details

#get_image_count(page_number = 1, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Gets number of images in a specified page

@param  number page_number
@param  string folder_name
@param  string storage_type
@param  string storage_name


17
18
19
20
21
22
23
24
25
26
# File 'lib/Pdf/extractor.rb', line 17

def get_image_count(page_number=1, folder_name='', storage_type = 'Aspose', storage_name = '')
  str_uri = "#{@base_uri}/pages/#{page_number}/images"
  str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,folder_name,storage_name,storage_type)

  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)
  stream_hash['Images']['List'].length
end

#get_image_custom_size(page_number = 1, image_index = 0, image_format = 'png', width = 100, height = 100, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Get the particular image from the specified page with the default image size @param int page_number @param int image_index @param string image_format @param int width @param int height

@param  string folder_name
@param  string storage_type
@param  string storage_name


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/Pdf/extractor.rb', line 65

def get_image_custom_size(page_number=1, image_index=0, image_format='png', width=100, height=100, folder_name='', storage_type = 'Aspose', storage_name = '')
  qry = Hash.new
  str_uri = "#{@base_uri}/pages/#{page_number}/images/#{image_index}"
  qry[:format] = image_format unless image_format.empty?
  qry[:width] = width
  qry[:height] = height
  str_uri = Aspose::Cloud::Common::Utils.build_uri(str_uri,qry)
  str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,folder_name,storage_name,storage_type)
  str_uri = str_uri[0..-2] if str_uri[-1].eql?('?')

  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.empty?
    output_path = "#{Aspose::Cloud::Common::AsposeApp.output_location}#{Aspose::Cloud::Common::Utils.get_filename(@filename)}_#{image_index}.#{image_format}"
    Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
  end
  valid_output
end

#get_image_default_size(page_number = 1, image_index = 0, image_format = 'png', folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Get the particular image from the specified page with the default image size @param number page_number @param number image_index @param string image_format

@param  string folder_name
@param  string storage_type
@param  string storage_name


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/Pdf/extractor.rb', line 36

def get_image_default_size(page_number=1, image_index=0, image_format='png', folder_name='', storage_type = 'Aspose', storage_name = '')
  str_uri = "#{@base_uri}/pages/#{page_number}/images/#{image_index}?"
  str_uri = "#{str_uri}format=#{image_format}" unless image_format.empty?
  str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,folder_name,storage_name,storage_type)
  str_uri = str_uri[0..-2] if str_uri[-1].eql?('?')

  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.empty?
    output_path = "#{Aspose::Cloud::Common::AsposeApp.output_location}#{Aspose::Cloud::Common::Utils.get_filename(@filename)}_#{image_index}.#{image_format}"
    Aspose::Cloud::Common::Utils.save_file(response_stream,output_path)
  end
  valid_output
end