Class: Pdfcrowd::ImageToPdfClient
- Inherits:
-
Object
- Object
- Pdfcrowd::ImageToPdfClient
- Defined in:
- lib/pdfcrowd.rb
Overview
Conversion from an image to PDF.
Instance Method Summary collapse
-
#convertFile(file) ⇒ Object
Convert a local file.
-
#convertFileToFile(file, file_path) ⇒ Object
Convert a local file and write the result to a local file.
-
#convertFileToStream(file, out_stream) ⇒ Object
Convert a local file and write the result to an output stream.
-
#convertRawData(data) ⇒ Object
Convert raw data.
-
#convertRawDataToFile(data, file_path) ⇒ Object
Convert raw data to a file.
-
#convertRawDataToStream(data, out_stream) ⇒ Object
Convert raw data and write the result to an output stream.
-
#convertUrl(url) ⇒ Object
Convert an image.
-
#convertUrlToFile(url, file_path) ⇒ Object
Convert an image and write the result to a local file.
-
#convertUrlToStream(url, out_stream) ⇒ Object
Convert an image and write the result to an output stream.
-
#getConsumedCreditCount ⇒ Object
Get the number of credits consumed by the last conversion.
-
#getDebugLogUrl ⇒ Object
Get the URL of the debug log for the last conversion.
-
#getJobId ⇒ Object
Get the job id.
-
#getOutputSize ⇒ Object
Get the size of the output in bytes.
-
#getRemainingCreditCount ⇒ Object
Get the number of conversion credits available in your account.
-
#initialize(user_name, api_key) ⇒ ImageToPdfClient
constructor
Constructor for the Pdfcrowd API client.
-
#setDebugLog(debug_log) ⇒ Object
Turn on the debug logging.
-
#setHttpProxy(http_proxy) ⇒ Object
A proxy server used by Pdfcrowd conversion process for accessing the source URLs with HTTP scheme.
-
#setHttpsProxy(https_proxy) ⇒ Object
A proxy server used by Pdfcrowd conversion process for accessing the source URLs with HTTPS scheme.
-
#setProxy(host, port, user_name, password) ⇒ Object
Specifies an HTTP proxy that the API client library will use to connect to the internet.
-
#setResize(resize) ⇒ Object
Resize the image.
-
#setRetryCount(retry_count) ⇒ Object
Specifies the number of retries when the 502 HTTP status code is received.
-
#setRotate(rotate) ⇒ Object
Rotate the image.
-
#setTag(tag) ⇒ Object
Tag the conversion with a custom value.
-
#setUseHttp(use_http) ⇒ Object
Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
-
#setUserAgent(user_agent) ⇒ Object
Set a custom user agent HTTP header.
Constructor Details
#initialize(user_name, api_key) ⇒ ImageToPdfClient
Constructor for the Pdfcrowd API client.
-
user_name
- Your username at Pdfcrowd. -
api_key
- Your API key.
3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 |
# File 'lib/pdfcrowd.rb', line 3098 def initialize(user_name, api_key) @helper = ConnectionHelper.new(user_name, api_key) @fields = { 'input_format'=>'image', 'output_format'=>'pdf' } @file_id = 1 @files = {} @raw_data = {} end |
Instance Method Details
#convertFile(file) ⇒ Object
Convert a local file.
-
file
- The path to a local file to convert. The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). The file must exist and not be empty. -
Returns - Byte array containing the conversion output.
3159 3160 3161 3162 3163 3164 3165 3166 |
# File 'lib/pdfcrowd.rb', line 3159 def convertFile(file) if (!(File.file?(file) && !File.zero?(file))) raise Error.new(Pdfcrowd.(file, "file", "image-to-pdf", "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
Convert a local file and write the result to a local file.
-
file
- The path to a local file to convert. The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). The file must exist and not be empty. -
file_path
- The output file path. The string must not be empty.
3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 |
# File 'lib/pdfcrowd.rb', line 3185 def convertFileToFile(file, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "file_path", "image-to-pdf", "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
Convert a local file and write the result to an output stream.
-
file
- The path to a local file to convert. The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). The file must exist and not be empty. -
out_stream
- The output stream that will contain the conversion output.
3172 3173 3174 3175 3176 3177 3178 3179 |
# File 'lib/pdfcrowd.rb', line 3172 def convertFileToStream(file, out_stream) if (!(File.file?(file) && !File.zero?(file))) raise Error.new(Pdfcrowd.(file, "file", "image-to-pdf", "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
Convert raw data.
-
data
- The raw content to be converted. -
Returns - Byte array with the output.
3205 3206 3207 3208 |
# File 'lib/pdfcrowd.rb', line 3205 def convertRawData(data) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data) end |
#convertRawDataToFile(data, file_path) ⇒ Object
Convert raw data to a file.
-
data
- The raw content to be converted. -
file_path
- The output file path. The string must not be empty.
3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 |
# File 'lib/pdfcrowd.rb', line 3223 def convertRawDataToFile(data, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "file_path", "image-to-pdf", "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
Convert raw data and write the result to an output stream.
-
data
- The raw content to be converted. -
out_stream
- The output stream that will contain the conversion output.
3214 3215 3216 3217 |
# File 'lib/pdfcrowd.rb', line 3214 def convertRawDataToStream(data, out_stream) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertUrl(url) ⇒ Object
Convert an image.
-
url
- The address of the image to convert. The supported protocols are http:// and https://. -
Returns - Byte array containing the conversion output.
3113 3114 3115 3116 3117 3118 3119 3120 |
# File 'lib/pdfcrowd.rb', line 3113 def convertUrl(url) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.(url, "url", "image-to-pdf", "The 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
Convert an image and write the result to a local file.
-
url
- The address of the image to convert. The supported protocols are http:// and https://. -
file_path
- The output file path. The string must not be empty.
3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 |
# File 'lib/pdfcrowd.rb', line 3139 def convertUrlToFile(url, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "file_path", "image-to-pdf", "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
Convert an image and write the result to an output stream.
-
url
- The address of the image to convert. The supported protocols are http:// and https://. -
out_stream
- The output stream that will contain the conversion output.
3126 3127 3128 3129 3130 3131 3132 3133 |
# File 'lib/pdfcrowd.rb', line 3126 def convertUrlToStream(url, out_stream) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.(url, "url", "image-to-pdf", "The 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
Get the number of credits consumed by the last conversion.
-
Returns - The number of credits.
3283 3284 3285 |
# File 'lib/pdfcrowd.rb', line 3283 def getConsumedCreditCount() return @helper.getConsumedCreditCount() end |
#getDebugLogUrl ⇒ Object
Get the URL of the debug log for the last conversion.
-
Returns - The link to the debug log.
3268 3269 3270 |
# File 'lib/pdfcrowd.rb', line 3268 def getDebugLogUrl() return @helper.getDebugLogUrl() end |
#getJobId ⇒ Object
Get the job id.
-
Returns - The unique job identifier.
3289 3290 3291 |
# File 'lib/pdfcrowd.rb', line 3289 def getJobId() return @helper.getJobId() end |
#getOutputSize ⇒ Object
Get the size of the output in bytes.
-
Returns - The count of bytes.
3295 3296 3297 |
# File 'lib/pdfcrowd.rb', line 3295 def getOutputSize() return @helper.getOutputSize() end |
#getRemainingCreditCount ⇒ Object
Get the number of conversion credits available in your account. This method can only be called after a call to one of the convertXYZ methods. The returned value can differ from the actual count if you run parallel conversions. The special value 999999 is returned if the information is not available.
-
Returns - The number of credits.
3277 3278 3279 |
# File 'lib/pdfcrowd.rb', line 3277 def getRemainingCreditCount() return @helper.getRemainingCreditCount() end |
#setDebugLog(debug_log) ⇒ Object
Turn on the debug logging. Details about the conversion are stored in the debug log. The URL of the log can be obtained from the getDebugLogUrl method or available in conversion statistics.
-
debug_log
- Set to true to enable the debug logging. -
Returns - The converter object.
3261 3262 3263 3264 |
# File 'lib/pdfcrowd.rb', line 3261 def setDebugLog(debug_log) @fields['debug_log'] = debug_log self end |
#setHttpProxy(http_proxy) ⇒ Object
A proxy server used by Pdfcrowd conversion process for accessing the source URLs with HTTP scheme. It can help to circumvent regional restrictions or provide limited access to your intranet.
-
http_proxy
- The value must have format DOMAIN_OR_IP_ADDRESS:PORT. -
Returns - The converter object.
3312 3313 3314 3315 3316 3317 3318 3319 |
# File 'lib/pdfcrowd.rb', line 3312 def setHttpProxy(http_proxy) unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(http_proxy) raise Error.new(Pdfcrowd.(http_proxy, "http_proxy", "image-to-pdf", "The value must have format DOMAIN_OR_IP_ADDRESS:PORT.", "set_http_proxy"), 470); end @fields['http_proxy'] = http_proxy self end |
#setHttpsProxy(https_proxy) ⇒ Object
A proxy server used by Pdfcrowd conversion process for accessing the source URLs with HTTPS scheme. It can help to circumvent regional restrictions or provide limited access to your intranet.
-
https_proxy
- The value must have format DOMAIN_OR_IP_ADDRESS:PORT. -
Returns - The converter object.
3325 3326 3327 3328 3329 3330 3331 3332 |
# File 'lib/pdfcrowd.rb', line 3325 def setHttpsProxy(https_proxy) unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(https_proxy) raise Error.new(Pdfcrowd.(https_proxy, "https_proxy", "image-to-pdf", "The value must have format DOMAIN_OR_IP_ADDRESS:PORT.", "set_https_proxy"), 470); end @fields['https_proxy'] = https_proxy self end |
#setProxy(host, port, user_name, password) ⇒ Object
Specifies an HTTP proxy that the API client library will use to connect to the internet.
-
host
- The proxy hostname. -
port
- The proxy port. -
user_name
- The username. -
password
- The password. -
Returns - The converter object.
3359 3360 3361 3362 |
# File 'lib/pdfcrowd.rb', line 3359 def setProxy(host, port, user_name, password) @helper.setProxy(host, port, user_name, password) self end |
#setResize(resize) ⇒ Object
Resize the image.
-
resize
- The resize percentage or new image dimensions. -
Returns - The converter object.
3243 3244 3245 3246 |
# File 'lib/pdfcrowd.rb', line 3243 def setResize(resize) @fields['resize'] = resize self end |
#setRetryCount(retry_count) ⇒ Object
Specifies the number of retries when the 502 HTTP status code is received. The 502 status code indicates a temporary network issue. This feature can be disabled by setting to 0.
-
retry_count
- Number of retries wanted. -
Returns - The converter object.
3368 3369 3370 3371 |
# File 'lib/pdfcrowd.rb', line 3368 def setRetryCount(retry_count) @helper.setRetryCount(retry_count) self end |
#setRotate(rotate) ⇒ Object
Rotate the image.
-
rotate
- The rotation specified in degrees. -
Returns - The converter object.
3252 3253 3254 3255 |
# File 'lib/pdfcrowd.rb', line 3252 def setRotate(rotate) @fields['rotate'] = rotate self end |
#setTag(tag) ⇒ Object
Tag the conversion with a custom value. The tag is used in conversion statistics. A value longer than 32 characters is cut off.
-
tag
- A string with the custom tag. -
Returns - The converter object.
3303 3304 3305 3306 |
# File 'lib/pdfcrowd.rb', line 3303 def setTag(tag) @fields['tag'] = tag self end |
#setUseHttp(use_http) ⇒ Object
Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
-
use_http
- Set to true to use HTTP. -
Returns - The converter object.
3338 3339 3340 3341 |
# File 'lib/pdfcrowd.rb', line 3338 def setUseHttp(use_http) @helper.setUseHttp(use_http) self end |
#setUserAgent(user_agent) ⇒ Object
Set a custom user agent HTTP header. It can be usefull if you are behind some proxy or firewall.
-
user_agent
- The user agent string. -
Returns - The converter object.
3347 3348 3349 3350 |
# File 'lib/pdfcrowd.rb', line 3347 def setUserAgent(user_agent) @helper.setUserAgent(user_agent) self end |