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.
5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 |
# File 'lib/pdfcrowd.rb', line 5135 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
5184 5185 5186 5187 5188 5189 5190 5191 |
# File 'lib/pdfcrowd.rb', line 5184 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
5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 |
# File 'lib/pdfcrowd.rb', line 5204 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
5194 5195 5196 5197 5198 5199 5200 5201 |
# File 'lib/pdfcrowd.rb', line 5194 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
5221 5222 5223 5224 |
# File 'lib/pdfcrowd.rb', line 5221 def convertRawData(data) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data) end |
#convertRawDataToFile(data, file_path) ⇒ Object
5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 |
# File 'lib/pdfcrowd.rb', line 5233 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
5227 5228 5229 5230 |
# File 'lib/pdfcrowd.rb', line 5227 def convertRawDataToStream(data, out_stream) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertStream(in_stream) ⇒ Object
5250 5251 5252 5253 |
# File 'lib/pdfcrowd.rb', line 5250 def convertStream(in_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data) end |
#convertStreamToFile(in_stream, file_path) ⇒ Object
5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 |
# File 'lib/pdfcrowd.rb', line 5262 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
5256 5257 5258 5259 |
# File 'lib/pdfcrowd.rb', line 5256 def convertStreamToStream(in_stream, out_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertUrl(url) ⇒ Object
5147 5148 5149 5150 5151 5152 5153 5154 |
# File 'lib/pdfcrowd.rb', line 5147 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
5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 |
# File 'lib/pdfcrowd.rb', line 5167 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
5157 5158 5159 5160 5161 5162 5163 5164 |
# File 'lib/pdfcrowd.rb', line 5157 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
5399 5400 5401 |
# File 'lib/pdfcrowd.rb', line 5399 def getConsumedCreditCount() return @helper.getConsumedCreditCount() end |
#getDebugLogUrl ⇒ Object
5389 5390 5391 |
# File 'lib/pdfcrowd.rb', line 5389 def getDebugLogUrl() return @helper.getDebugLogUrl() end |
#getJobId ⇒ Object
5404 5405 5406 |
# File 'lib/pdfcrowd.rb', line 5404 def getJobId() return @helper.getJobId() end |
#getOutputSize ⇒ Object
5414 5415 5416 |
# File 'lib/pdfcrowd.rb', line 5414 def getOutputSize() return @helper.getOutputSize() end |
#getPageCount ⇒ Object
5409 5410 5411 |
# File 'lib/pdfcrowd.rb', line 5409 def getPageCount() return @helper.getPageCount() end |
#getRemainingCreditCount ⇒ Object
5394 5395 5396 |
# File 'lib/pdfcrowd.rb', line 5394 def getRemainingCreditCount() return @helper.getRemainingCreditCount() end |
#getVersion ⇒ Object
5419 5420 5421 |
# File 'lib/pdfcrowd.rb', line 5419 def getVersion() return "client " + CLIENT_VERSION + ", API v2, converter " + @helper.getConverterVersion() end |
#isZippedOutput ⇒ Object
5311 5312 5313 |
# File 'lib/pdfcrowd.rb', line 5311 def isZippedOutput() @fields.fetch('force_zip', false) == true || getPageCount() > 1 end |
#setClientUserAgent(agent) ⇒ Object
5456 5457 5458 5459 |
# File 'lib/pdfcrowd.rb', line 5456 def setClientUserAgent(agent) @helper.setUserAgent(agent) self end |
#setCropArea(x, y, width, height) ⇒ Object
5368 5369 5370 5371 5372 5373 5374 |
# File 'lib/pdfcrowd.rb', line 5368 def setCropArea(x, y, width, height) setCropAreaX(x) setCropAreaY(y) setCropAreaWidth(width) setCropAreaHeight(height) self end |
#setCropAreaHeight(height) ⇒ Object
5358 5359 5360 5361 5362 5363 5364 5365 |
# File 'lib/pdfcrowd.rb', line 5358 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
5348 5349 5350 5351 5352 5353 5354 5355 |
# File 'lib/pdfcrowd.rb', line 5348 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
5328 5329 5330 5331 5332 5333 5334 5335 |
# File 'lib/pdfcrowd.rb', line 5328 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
5338 5339 5340 5341 5342 5343 5344 5345 |
# File 'lib/pdfcrowd.rb', line 5338 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
5383 5384 5385 5386 |
# File 'lib/pdfcrowd.rb', line 5383 def setDebugLog(value) @fields['debug_log'] = value self end |
#setDpi(dpi) ⇒ Object
5305 5306 5307 5308 |
# File 'lib/pdfcrowd.rb', line 5305 def setDpi(dpi) @fields['dpi'] = dpi self end |
#setForceZip(value) ⇒ Object
5316 5317 5318 5319 |
# File 'lib/pdfcrowd.rb', line 5316 def setForceZip(value) @fields['force_zip'] = value self end |
#setHttpProxy(proxy) ⇒ Object
5430 5431 5432 5433 5434 5435 5436 5437 |
# File 'lib/pdfcrowd.rb', line 5430 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
5440 5441 5442 5443 5444 5445 5446 5447 |
# File 'lib/pdfcrowd.rb', line 5440 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
5279 5280 5281 5282 5283 5284 5285 5286 |
# File 'lib/pdfcrowd.rb', line 5279 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
5289 5290 5291 5292 |
# File 'lib/pdfcrowd.rb', line 5289 def setPdfPassword(password) @fields['pdf_password'] = password self end |
#setPrintPageRange(pages) ⇒ Object
5295 5296 5297 5298 5299 5300 5301 5302 |
# File 'lib/pdfcrowd.rb', line 5295 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
5468 5469 5470 5471 |
# File 'lib/pdfcrowd.rb', line 5468 def setProxy(host, port, user_name, password) @helper.setProxy(host, port, user_name, password) self end |
#setRetryCount(count) ⇒ Object
5474 5475 5476 5477 |
# File 'lib/pdfcrowd.rb', line 5474 def setRetryCount(count) @helper.setRetryCount(count) self end |
#setTag(tag) ⇒ Object
5424 5425 5426 5427 |
# File 'lib/pdfcrowd.rb', line 5424 def setTag(tag) @fields['tag'] = tag self end |
#setUseCropbox(value) ⇒ Object
5322 5323 5324 5325 |
# File 'lib/pdfcrowd.rb', line 5322 def setUseCropbox(value) @fields['use_cropbox'] = value self end |
#setUseGrayscale(value) ⇒ Object
5377 5378 5379 5380 |
# File 'lib/pdfcrowd.rb', line 5377 def setUseGrayscale(value) @fields['use_grayscale'] = value self end |
#setUseHttp(value) ⇒ Object
5450 5451 5452 5453 |
# File 'lib/pdfcrowd.rb', line 5450 def setUseHttp(value) @helper.setUseHttp(value) self end |
#setUserAgent(agent) ⇒ Object
5462 5463 5464 5465 |
# File 'lib/pdfcrowd.rb', line 5462 def setUserAgent(agent) @helper.setUserAgent(agent) self end |