Class: Aspose::Cloud::Pdf::Converter
- Inherits:
-
Object
- Object
- Aspose::Cloud::Pdf::Converter
- Defined in:
- lib/Pdf/converter.rb
Instance Method Summary collapse
-
#convert(save_format, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object
convert a pdf document to given format.
-
#convert_by_url(url, save_format, output_file, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object
Convert PDF from Remote Server to other Formats.
-
#convert_local_file(input_file, output_file, save_format) ⇒ Object
convert a local pdf document to given format without use of storage.
-
#convert_to_image(page_number, image_format, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object
convert a particular page to image with default size.
-
#convert_to_image_by_size(page_number, image_format, width = 0, height = 0, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object
convert a particular page to image with specified size.
-
#initialize(filename) ⇒ Converter
constructor
A new instance of Converter.
Constructor Details
Instance Method Details
#convert(save_format, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object
convert a pdf document to given format
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/Pdf/converter.rb', line 67 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) save_format = 'zip' if save_format.eql?('html') 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) end valid_output end |
#convert_by_url(url, save_format, output_file, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object
Convert PDF from Remote Server to other Formats
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/Pdf/converter.rb', line 111 def convert_by_url(url, save_format, output_file, folder_name = '', storage_type = 'Aspose', storage_name = '') raise 'url not specified.' if url.empty? raise 'save_format not specified.' if save_format.empty? raise 'output_file not specified.' if output_file.empty? str_uri = Aspose::Cloud::Common::Product.product_uri + "/pdf/convert?url=#{url}&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.put(signed_str_uri, {:accept=>'application/json'}) valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream) save_format = 'zip' if save_format.eql?('html') if valid_output.empty? output_path = "#{Aspose::Cloud::Common::AsposeApp.output_location}#{Aspose::Cloud::Common::Utils.get_filename(output_file)}.#{save_format}" Aspose::Cloud::Common::Utils.save_file(response_stream,output_path) end valid_output end |
#convert_local_file(input_file, output_file, save_format) ⇒ Object
convert a local pdf document to given format without use of storage
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/Pdf/converter.rb', line 89 def convert_local_file(input_file, output_file, save_format) raise 'input_file not specified.' if input_file.empty? raise 'output_file not specified.' if output_file.empty? raise 'save_format not specified.' if save_format.empty? str_uri = "#{Aspose::Cloud::Common::Product.product_uri}/pdf/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, signed_str_uri) valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream) save_format = 'zip' if save_format.eql?('html') if valid_output.empty? output_path = "#{Aspose::Cloud::Common::AsposeApp.output_location}#{Aspose::Cloud::Common::Utils.get_filename(output_file)}.#{save_format}" Aspose::Cloud::Common::Utils.save_file(response_stream,output_path) end valid_output end |
#convert_to_image(page_number, image_format, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object
convert a particular page to image with default size
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/Pdf/converter.rb', line 13 def convert_to_image(page_number, image_format, folder_name = '', storage_type = 'Aspose', storage_name = '') raise 'page_number not specified.' if page_number.nil? raise 'image_format not specified.' if image_format.empty? qry = Hash.new str_uri = "#{@base_uri}/pages/#{page_number}" qry[:format] = image_format 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) 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)}_#{page_number}.#{image_format}" Aspose::Cloud::Common::Utils.save_file(response_stream,output_path) end valid_output end |
#convert_to_image_by_size(page_number, image_format, width = 0, height = 0, folder_name = '', storage_type = 'Aspose', storage_name = '') ⇒ Object
convert a particular page to image with specified size
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/Pdf/converter.rb', line 39 def convert_to_image_by_size(page_number, image_format, width=0, height=0, folder_name = '', storage_type = 'Aspose', storage_name = '') raise 'page_number not specified.' if page_number.nil? raise 'image_format not specified.' if image_format.empty? qry = Hash.new str_uri = "#{@base_uri}/pages/#{page_number}" qry[:format] = image_format qry[:width] = width unless width <= 0 qry[:height] = width unless height <= 0 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) 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)}_#{page_number}.#{image_format}" Aspose::Cloud::Common::Utils.save_file(response_stream,output_path) end valid_output end |