Class: Pdfcrowd::PdfToImageClient
- Inherits:
-
Object
- Object
- Pdfcrowd::PdfToImageClient
- Defined in:
- lib/pdfcrowd.rb
Overview
Conversion from PDF to image.
Instance Method Summary collapse
- #convertFile(file) ⇒ Object
- #convertFileToFile(file, file_path) ⇒ Object
- #convertFileToStream(file, out_stream) ⇒ Object
- #convertRawData(data) ⇒ Object
- #convertRawDataToFile(data, file_path) ⇒ Object
- #convertRawDataToStream(data, out_stream) ⇒ Object
- #convertStream(in_stream) ⇒ Object
- #convertStreamToFile(in_stream, file_path) ⇒ Object
- #convertStreamToStream(in_stream, out_stream) ⇒ Object
- #convertUrl(url) ⇒ Object
- #convertUrlToFile(url, file_path) ⇒ Object
- #convertUrlToStream(url, out_stream) ⇒ Object
- #getConsumedCreditCount ⇒ Object
- #getDebugLogUrl ⇒ Object
- #getJobId ⇒ Object
- #getOutputSize ⇒ Object
- #getPageCount ⇒ Object
- #getRemainingCreditCount ⇒ Object
- #getVersion ⇒ Object
-
#initialize(user_name, api_key) ⇒ PdfToImageClient
constructor
A new instance of PdfToImageClient.
- #isZippedOutput ⇒ Object
- #setClientUserAgent(agent) ⇒ Object
- #setCropArea(x, y, width, height) ⇒ Object
- #setCropAreaHeight(height) ⇒ Object
- #setCropAreaWidth(width) ⇒ Object
- #setCropAreaX(x) ⇒ Object
- #setCropAreaY(y) ⇒ Object
- #setDebugLog(value) ⇒ Object
- #setDpi(dpi) ⇒ Object
- #setForceZip(value) ⇒ Object
- #setHttpProxy(proxy) ⇒ Object
- #setHttpsProxy(proxy) ⇒ Object
- #setOutputFormat(output_format) ⇒ Object
- #setPdfPassword(password) ⇒ Object
- #setPrintPageRange(pages) ⇒ Object
- #setProxy(host, port, user_name, password) ⇒ Object
- #setRetryCount(count) ⇒ Object
- #setTag(tag) ⇒ Object
- #setUseCropbox(value) ⇒ Object
- #setUseGrayscale(value) ⇒ Object
- #setUseHttp(value) ⇒ Object
- #setUserAgent(agent) ⇒ Object
Constructor Details
#initialize(user_name, api_key) ⇒ PdfToImageClient
Returns a new instance of PdfToImageClient.
5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 |
# File 'lib/pdfcrowd.rb', line 5086 def initialize(user_name, api_key) @helper = ConnectionHelper.new(user_name, api_key) @fields = { 'input_format'=>'pdf', 'output_format'=>'png' } @file_id = 1 @files = {} @raw_data = {} end |
Instance Method Details
#convertFile(file) ⇒ Object
5135 5136 5137 5138 5139 5140 5141 5142 |
# File 'lib/pdfcrowd.rb', line 5135 def convertFile(file) if (!(File.file?(file) && !File.zero?(file))) raise Error.new(Pdfcrowd.(file, "convertFile", "pdf-to-image", "The file must exist and not be empty.", "convert_file"), 470); end @files['file'] = file @helper.post(@fields, @files, @raw_data) end |
#convertFileToFile(file, file_path) ⇒ Object
5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 |
# File 'lib/pdfcrowd.rb', line 5155 def convertFileToFile(file, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "convertFileToFile::file_path", "pdf-to-image", "The string must not be empty.", "convert_file_to_file"), 470); end output_file = open(file_path, "wb") begin convertFileToStream(file, output_file) output_file.close() rescue Error => why output_file.close() FileUtils.rm(file_path) raise end end |
#convertFileToStream(file, out_stream) ⇒ Object
5145 5146 5147 5148 5149 5150 5151 5152 |
# File 'lib/pdfcrowd.rb', line 5145 def convertFileToStream(file, out_stream) if (!(File.file?(file) && !File.zero?(file))) raise Error.new(Pdfcrowd.(file, "convertFileToStream::file", "pdf-to-image", "The file must exist and not be empty.", "convert_file_to_stream"), 470); end @files['file'] = file @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertRawData(data) ⇒ Object
5172 5173 5174 5175 |
# File 'lib/pdfcrowd.rb', line 5172 def convertRawData(data) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data) end |
#convertRawDataToFile(data, file_path) ⇒ Object
5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 |
# File 'lib/pdfcrowd.rb', line 5184 def convertRawDataToFile(data, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "convertRawDataToFile::file_path", "pdf-to-image", "The string must not be empty.", "convert_raw_data_to_file"), 470); end output_file = open(file_path, "wb") begin convertRawDataToStream(data, output_file) output_file.close() rescue Error => why output_file.close() FileUtils.rm(file_path) raise end end |
#convertRawDataToStream(data, out_stream) ⇒ Object
5178 5179 5180 5181 |
# File 'lib/pdfcrowd.rb', line 5178 def convertRawDataToStream(data, out_stream) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertStream(in_stream) ⇒ Object
5201 5202 5203 5204 |
# File 'lib/pdfcrowd.rb', line 5201 def convertStream(in_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data) end |
#convertStreamToFile(in_stream, file_path) ⇒ Object
5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 |
# File 'lib/pdfcrowd.rb', line 5213 def convertStreamToFile(in_stream, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "convertStreamToFile::file_path", "pdf-to-image", "The string must not be empty.", "convert_stream_to_file"), 470); end output_file = open(file_path, "wb") begin convertStreamToStream(in_stream, output_file) output_file.close() rescue Error => why output_file.close() FileUtils.rm(file_path) raise end end |
#convertStreamToStream(in_stream, out_stream) ⇒ Object
5207 5208 5209 5210 |
# File 'lib/pdfcrowd.rb', line 5207 def convertStreamToStream(in_stream, out_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertUrl(url) ⇒ Object
5098 5099 5100 5101 5102 5103 5104 5105 |
# File 'lib/pdfcrowd.rb', line 5098 def convertUrl(url) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.(url, "convertUrl", "pdf-to-image", "Supported protocols are http:// and https://.", "convert_url"), 470); end @fields['url'] = url @helper.post(@fields, @files, @raw_data) end |
#convertUrlToFile(url, file_path) ⇒ Object
5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 |
# File 'lib/pdfcrowd.rb', line 5118 def convertUrlToFile(url, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "convertUrlToFile::file_path", "pdf-to-image", "The string must not be empty.", "convert_url_to_file"), 470); end output_file = open(file_path, "wb") begin convertUrlToStream(url, output_file) output_file.close() rescue Error => why output_file.close() FileUtils.rm(file_path) raise end end |
#convertUrlToStream(url, out_stream) ⇒ Object
5108 5109 5110 5111 5112 5113 5114 5115 |
# File 'lib/pdfcrowd.rb', line 5108 def convertUrlToStream(url, out_stream) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.(url, "convertUrlToStream::url", "pdf-to-image", "Supported protocols are http:// and https://.", "convert_url_to_stream"), 470); end @fields['url'] = url @helper.post(@fields, @files, @raw_data, out_stream) end |
#getConsumedCreditCount ⇒ Object
5350 5351 5352 |
# File 'lib/pdfcrowd.rb', line 5350 def getConsumedCreditCount() return @helper.getConsumedCreditCount() end |
#getDebugLogUrl ⇒ Object
5340 5341 5342 |
# File 'lib/pdfcrowd.rb', line 5340 def getDebugLogUrl() return @helper.getDebugLogUrl() end |
#getJobId ⇒ Object
5355 5356 5357 |
# File 'lib/pdfcrowd.rb', line 5355 def getJobId() return @helper.getJobId() end |
#getOutputSize ⇒ Object
5365 5366 5367 |
# File 'lib/pdfcrowd.rb', line 5365 def getOutputSize() return @helper.getOutputSize() end |
#getPageCount ⇒ Object
5360 5361 5362 |
# File 'lib/pdfcrowd.rb', line 5360 def getPageCount() return @helper.getPageCount() end |
#getRemainingCreditCount ⇒ Object
5345 5346 5347 |
# File 'lib/pdfcrowd.rb', line 5345 def getRemainingCreditCount() return @helper.getRemainingCreditCount() end |
#getVersion ⇒ Object
5370 5371 5372 |
# File 'lib/pdfcrowd.rb', line 5370 def getVersion() return "client " + CLIENT_VERSION + ", API v2, converter " + @helper.getConverterVersion() end |
#isZippedOutput ⇒ Object
5262 5263 5264 |
# File 'lib/pdfcrowd.rb', line 5262 def isZippedOutput() @fields.fetch('force_zip', false) == true || getPageCount() > 1 end |
#setClientUserAgent(agent) ⇒ Object
5407 5408 5409 5410 |
# File 'lib/pdfcrowd.rb', line 5407 def setClientUserAgent(agent) @helper.setUserAgent(agent) self end |
#setCropArea(x, y, width, height) ⇒ Object
5319 5320 5321 5322 5323 5324 5325 |
# File 'lib/pdfcrowd.rb', line 5319 def setCropArea(x, y, width, height) setCropAreaX(x) setCropAreaY(y) setCropAreaWidth(width) setCropAreaHeight(height) self end |
#setCropAreaHeight(height) ⇒ Object
5309 5310 5311 5312 5313 5314 5315 5316 |
# File 'lib/pdfcrowd.rb', line 5309 def setCropAreaHeight(height) if (!(Integer(height) >= 0)) raise Error.new(Pdfcrowd.(height, "setCropAreaHeight", "pdf-to-image", "Must be a positive integer or 0.", "set_crop_area_height"), 470); end @fields['crop_area_height'] = height self end |
#setCropAreaWidth(width) ⇒ Object
5299 5300 5301 5302 5303 5304 5305 5306 |
# File 'lib/pdfcrowd.rb', line 5299 def setCropAreaWidth(width) if (!(Integer(width) >= 0)) raise Error.new(Pdfcrowd.(width, "setCropAreaWidth", "pdf-to-image", "Must be a positive integer or 0.", "set_crop_area_width"), 470); end @fields['crop_area_width'] = width self end |
#setCropAreaX(x) ⇒ Object
5279 5280 5281 5282 5283 5284 5285 5286 |
# File 'lib/pdfcrowd.rb', line 5279 def setCropAreaX(x) if (!(Integer(x) >= 0)) raise Error.new(Pdfcrowd.(x, "setCropAreaX", "pdf-to-image", "Must be a positive integer or 0.", "set_crop_area_x"), 470); end @fields['crop_area_x'] = x self end |
#setCropAreaY(y) ⇒ Object
5289 5290 5291 5292 5293 5294 5295 5296 |
# File 'lib/pdfcrowd.rb', line 5289 def setCropAreaY(y) if (!(Integer(y) >= 0)) raise Error.new(Pdfcrowd.(y, "setCropAreaY", "pdf-to-image", "Must be a positive integer or 0.", "set_crop_area_y"), 470); end @fields['crop_area_y'] = y self end |
#setDebugLog(value) ⇒ Object
5334 5335 5336 5337 |
# File 'lib/pdfcrowd.rb', line 5334 def setDebugLog(value) @fields['debug_log'] = value self end |
#setDpi(dpi) ⇒ Object
5256 5257 5258 5259 |
# File 'lib/pdfcrowd.rb', line 5256 def setDpi(dpi) @fields['dpi'] = dpi self end |
#setForceZip(value) ⇒ Object
5267 5268 5269 5270 |
# File 'lib/pdfcrowd.rb', line 5267 def setForceZip(value) @fields['force_zip'] = value self end |
#setHttpProxy(proxy) ⇒ Object
5381 5382 5383 5384 5385 5386 5387 5388 |
# File 'lib/pdfcrowd.rb', line 5381 def setHttpProxy(proxy) unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(proxy) raise Error.new(Pdfcrowd.(proxy, "setHttpProxy", "pdf-to-image", "The value must have format DOMAIN_OR_IP_ADDRESS:PORT.", "set_http_proxy"), 470); end @fields['http_proxy'] = proxy self end |
#setHttpsProxy(proxy) ⇒ Object
5391 5392 5393 5394 5395 5396 5397 5398 |
# File 'lib/pdfcrowd.rb', line 5391 def setHttpsProxy(proxy) unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(proxy) raise Error.new(Pdfcrowd.(proxy, "setHttpsProxy", "pdf-to-image", "The value must have format DOMAIN_OR_IP_ADDRESS:PORT.", "set_https_proxy"), 470); end @fields['https_proxy'] = proxy self end |
#setOutputFormat(output_format) ⇒ Object
5230 5231 5232 5233 5234 5235 5236 5237 |
# File 'lib/pdfcrowd.rb', line 5230 def setOutputFormat(output_format) unless /(?i)^(png|jpg|gif|tiff|bmp|ico|ppm|pgm|pbm|pnm|psb|pct|ras|tga|sgi|sun|webp)$/.match(output_format) raise Error.new(Pdfcrowd.(output_format, "setOutputFormat", "pdf-to-image", "Allowed values are png, jpg, gif, tiff, bmp, ico, ppm, pgm, pbm, pnm, psb, pct, ras, tga, sgi, sun, webp.", "set_output_format"), 470); end @fields['output_format'] = output_format self end |
#setPdfPassword(password) ⇒ Object
5240 5241 5242 5243 |
# File 'lib/pdfcrowd.rb', line 5240 def setPdfPassword(password) @fields['pdf_password'] = password self end |
#setPrintPageRange(pages) ⇒ Object
5246 5247 5248 5249 5250 5251 5252 5253 |
# File 'lib/pdfcrowd.rb', line 5246 def setPrintPageRange(pages) unless /^(?:\s*(?:\d+|(?:\d*\s*\-\s*\d+)|(?:\d+\s*\-\s*\d*))\s*,\s*)*\s*(?:\d+|(?:\d*\s*\-\s*\d+)|(?:\d+\s*\-\s*\d*))\s*$/.match(pages) raise Error.new(Pdfcrowd.(pages, "setPrintPageRange", "pdf-to-image", "A comma separated list of page numbers or ranges.", "set_print_page_range"), 470); end @fields['print_page_range'] = pages self end |
#setProxy(host, port, user_name, password) ⇒ Object
5419 5420 5421 5422 |
# File 'lib/pdfcrowd.rb', line 5419 def setProxy(host, port, user_name, password) @helper.setProxy(host, port, user_name, password) self end |
#setRetryCount(count) ⇒ Object
5425 5426 5427 5428 |
# File 'lib/pdfcrowd.rb', line 5425 def setRetryCount(count) @helper.setRetryCount(count) self end |
#setTag(tag) ⇒ Object
5375 5376 5377 5378 |
# File 'lib/pdfcrowd.rb', line 5375 def setTag(tag) @fields['tag'] = tag self end |
#setUseCropbox(value) ⇒ Object
5273 5274 5275 5276 |
# File 'lib/pdfcrowd.rb', line 5273 def setUseCropbox(value) @fields['use_cropbox'] = value self end |
#setUseGrayscale(value) ⇒ Object
5328 5329 5330 5331 |
# File 'lib/pdfcrowd.rb', line 5328 def setUseGrayscale(value) @fields['use_grayscale'] = value self end |
#setUseHttp(value) ⇒ Object
5401 5402 5403 5404 |
# File 'lib/pdfcrowd.rb', line 5401 def setUseHttp(value) @helper.setUseHttp(value) self end |
#setUserAgent(agent) ⇒ Object
5413 5414 5415 5416 |
# File 'lib/pdfcrowd.rb', line 5413 def setUserAgent(agent) @helper.setUserAgent(agent) self end |