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.



22
23
24
25
26
# File 'lib/Pdf/extractor.rb', line 22

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


34
35
36
37
38
39
40
41
42
43
# File 'lib/Pdf/extractor.rb', line 34

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


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/Pdf/extractor.rb', line 82

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


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/Pdf/extractor.rb', line 53

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