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.
2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 |
# File 'lib/pdfcrowd.rb', line 2936 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.
2997 2998 2999 3000 3001 3002 3003 3004 |
# File 'lib/pdfcrowd.rb', line 2997 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.
3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 |
# File 'lib/pdfcrowd.rb', line 3023 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.
3010 3011 3012 3013 3014 3015 3016 3017 |
# File 'lib/pdfcrowd.rb', line 3010 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.
3043 3044 3045 3046 |
# File 'lib/pdfcrowd.rb', line 3043 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.
3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 |
# File 'lib/pdfcrowd.rb', line 3061 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.
3052 3053 3054 3055 |
# File 'lib/pdfcrowd.rb', line 3052 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.
2951 2952 2953 2954 2955 2956 2957 2958 |
# File 'lib/pdfcrowd.rb', line 2951 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.
2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 |
# File 'lib/pdfcrowd.rb', line 2977 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.
2964 2965 2966 2967 2968 2969 2970 2971 |
# File 'lib/pdfcrowd.rb', line 2964 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.
3120 3121 3122 |
# File 'lib/pdfcrowd.rb', line 3120 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.
3106 3107 3108 |
# File 'lib/pdfcrowd.rb', line 3106 def getDebugLogUrl() return @helper.getDebugLogUrl() end |
#getJobId ⇒ Object
Get the job id.
-
Returns - The unique job identifier.
3126 3127 3128 |
# File 'lib/pdfcrowd.rb', line 3126 def getJobId() return @helper.getJobId() end |
#getOutputSize ⇒ Object
Get the size of the output in bytes.
-
Returns - The count of bytes.
3132 3133 3134 |
# File 'lib/pdfcrowd.rb', line 3132 def getOutputSize() return @helper.getOutputSize() end |
#getRemainingCreditCount ⇒ Object
Get the number of conversion credits available in your account. 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.
3114 3115 3116 |
# File 'lib/pdfcrowd.rb', line 3114 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.
3099 3100 3101 3102 |
# File 'lib/pdfcrowd.rb', line 3099 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.
3149 3150 3151 3152 3153 3154 3155 3156 |
# File 'lib/pdfcrowd.rb', line 3149 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.
3162 3163 3164 3165 3166 3167 3168 3169 |
# File 'lib/pdfcrowd.rb', line 3162 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.
3196 3197 3198 3199 |
# File 'lib/pdfcrowd.rb', line 3196 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.
3081 3082 3083 3084 |
# File 'lib/pdfcrowd.rb', line 3081 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.
3205 3206 3207 3208 |
# File 'lib/pdfcrowd.rb', line 3205 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.
3090 3091 3092 3093 |
# File 'lib/pdfcrowd.rb', line 3090 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.
3140 3141 3142 3143 |
# File 'lib/pdfcrowd.rb', line 3140 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.
3175 3176 3177 3178 |
# File 'lib/pdfcrowd.rb', line 3175 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.
3184 3185 3186 3187 |
# File 'lib/pdfcrowd.rb', line 3184 def setUserAgent(user_agent) @helper.setUserAgent(user_agent) self end |