Class: Aspose::Cloud::Words::Converter
- Inherits:
-
Object
- Object
- Aspose::Cloud::Words::Converter
- Defined in:
- lib/Words/converter.rb
Instance Method Summary collapse
-
#convert(save_format, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object
Convert Word to Images, Multipage TIFF, HTML, PDF and other File Format using Cloud Storage @param string save_format Return file format.
-
#convert_local_file(input_file_path, output_filename, save_format) ⇒ Object
Convert Word to other File Formats without using the Cloud Storage @param string input_file_path Path of the input file.
-
#convert_web_pages(str_xml, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object
Convert web pages to Word Documents @param xml str_xml Provide xml data.
-
#initialize(filename) ⇒ Converter
constructor
A new instance of Converter.
Constructor Details
#initialize(filename) ⇒ Converter
Returns a new instance of Converter.
5 6 7 8 9 |
# File 'lib/Words/converter.rb', line 5 def initialize(filename) @filename = filename raise 'filename not specified.' if filename.empty? @base_uri = Aspose::Cloud::Common::Product.product_uri + '/words/' + @filename end |
Instance Method Details
#convert(save_format, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object
Convert Word to Images, Multipage TIFF, HTML, PDF and other File Format using Cloud Storage
@param string save_format Return file format.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/Words/converter.rb', line 15 def convert(save_format, folder_name = '', storage_type = 'Aspose', storage_name = '') raise 'save_format not specified.' if save_format.empty? str_uri = "#{@base_uri}?format=#{save_format}" 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'}) 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)}.#{save_format}" Aspose::Cloud::Common::Utils.save_file(response_stream,output_path) else valid_output end end |
#convert_local_file(input_file_path, output_filename, save_format) ⇒ Object
Convert Word to other File Formats without using the Cloud Storage
@param string input_file_path Path of the input file.
@param string output_filename Name of the return file.
@param string save_format Return file format.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/Words/converter.rb', line 39 def convert_local_file(input_file_path, output_filename, save_format) raise 'input_file_path not specified.' if input_file_path.empty? raise 'output_filename not specified.' if output_filename.empty? raise 'save_format not specified.' if save_format.empty? str_uri = "#{Aspose::Cloud::Common::Product.product_uri}/words/convert?format=#{save_format}" signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = Aspose::Cloud::Common::Utils.upload_file_binary(input_file_path, signed_str_uri) valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream) if valid_output.empty? save_format = 'zip' if save_format.eql?('html') output_path = "#{Aspose::Cloud::Common::AsposeApp.output_location}#{Aspose::Cloud::Common::Utils.get_filename(output_filename)}.#{save_format}" Aspose::Cloud::Common::Utils.save_file(response_stream,output_path) end valid_output end |
#convert_web_pages(str_xml, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object
Convert web pages to Word Documents
@param xml str_xml Provide xml data.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/Words/converter.rb', line 62 def convert_web_pages(str_xml, folder_name = '', storage_type = 'Aspose', storage_name = '') raise 'str_xml not specified.' if str_xml.empty? str_uri = "#{Aspose::Cloud::Common::Product.product_uri}/words/loadWebDocument" 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 = Aspose::Cloud::Common::Utils.process_command(signed_str_uri,'POST','XML',str_xml) json = JSON.parse(response) if json['Code'] == 200 filename = json['SaveResult']['DestDocument']['Href'] Aspose::Cloud::Common::Utils.download_file(filename,filename,folder_name,storage_name,storage_type) end end |