Class: Aspose::Cloud::Pdf::Converter
- Inherits:
-
Object
- Object
- Aspose::Cloud::Pdf::Converter
- Defined in:
- lib/Pdf/converter.rb
Overview
converts pages or document into different formats
Instance Method Summary collapse
-
#convert(storage_name = '', folder = '', save_format = '') ⇒ Object
convert a document to SaveFormat.
-
#convert_local_file(input_file, output_filename, output_format) ⇒ Object
Convert PDF to different file format without using storage @param string inputFile @param string outputFilename @param string outputFormat.
-
#convert_to_image(page_number, image_format) ⇒ Object
convert a particular page to image with default size @param number page_number @param string image_format.
-
#convert_to_image_by_size(page_number, image_format, width = 0, height = 0) ⇒ Object
convert a particular page to image with specified size.
-
#initialize(filename) ⇒ Converter
constructor
A new instance of Converter.
Constructor Details
#initialize(filename) ⇒ Converter
Returns a new instance of Converter.
8 9 10 11 |
# File 'lib/Pdf/converter.rb', line 8 def initialize(filename) @filename = filename @save_format = 'pdf' end |
Instance Method Details
#convert(storage_name = '', folder = '', save_format = '') ⇒ Object
convert a document to SaveFormat
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 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/Pdf/converter.rb', line 98 def convert storage_name='', folder='', save_format='' begin if save_format.empty? == false @save_format = save_format end if @save_format == '' raise('save format not specified') end if(storage_name.empty? == true) str_uri = $product_uri + '/pdf/' + @filename + '?format=' + @save_format else str_uri = $product_uri + '/pdf/' + @filename + '?&format=' + @save_format + '&storage='+@save_format+'&folder='+folder end str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'}) valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream) if valid_output == '' if @save_format == 'html' save_format = 'zip' else save_format = @save_format end output_path = $out_put_location + Aspose::Cloud::Common::Utils.get_filename(@filename) + '.' + save_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 |
#convert_local_file(input_file, output_filename, output_format) ⇒ Object
Convert PDF to different file format without using storage
@param string inputFile
@param string outputFilename
@param string outputFormat
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/Pdf/converter.rb', line 146 def convert_local_file input_file,output_filename,output_format begin if input_file == '' raise('input file not specified') end if output_filename == '' raise('output file not specified') end if output_format == '' raise('output format not specified') end if not File.exist?(input_file) raise("input file doesn't exist.") end str_uri = $product_uri + '/pdf/convert?format=' + output_format str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = Aspose::Cloud::Common::Utils.upload_file_binary(input_file, str_signed_uri) valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream) if valid_output == '' if output_format == 'html' save_format = 'zip' else save_format = output_format end if output_filename == '' output_filename = Utils::get_filename(input_file) + '.' + save_format end output_path = $out_put_location + output_filename Aspose::Cloud::Common::Utils.save_file(response_stream,output_path) return '' else return valid_output end rescue Exception=>e print e end end |
#convert_to_image(page_number, image_format) ⇒ Object
convert a particular page to image with default size
@param number page_number
@param string image_format
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/Pdf/converter.rb', line 63 def convert_to_image page_number, image_format begin if page_number == '' raise('page number not specified') end if image_format == '' raise 'image format not specified' end str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s + '?format=' + image_format str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.get(str_signed_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) + '_' + page_number.to_s + '.' + image_format Aspose::Cloud::Common::Utils.save_file(response_stream,output_path) return '' else return valid_output end rescue Exception=>e print e end end |
#convert_to_image_by_size(page_number, image_format, width = 0, height = 0) ⇒ Object
convert a particular page to image with specified size
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/Pdf/converter.rb', line 19 def convert_to_image_by_size(page_number, image_format, width=0, height=0) begin if @filename == '' raise('filename not specified') end if page_number == '' raise('page number not specified') end if image_format == '' raise('image format not specified') end str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s + '?format=' + image_format + '&width=' + width.to_s + '&height=' + height.to_s str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.get(str_signed_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) + '_' + page_number.to_s + '.' + image_format Aspose::Cloud::Common::Utils.save_file(response_stream,output_path) return '' else return valid_output end rescue Exception=>e print e end end |