class Pdfcrowd::ImageToImageClient

Conversion from one image format to another image format.

Public Class Methods

new(user_name, api_key) click to toggle source

Constructor for the Pdfcrowd API client.

  • user_name - Your username at Pdfcrowd.

  • api_key - Your API key.

# File lib/pdfcrowd.rb, line 3117
def initialize(user_name, api_key)
    @helper = ConnectionHelper.new(user_name, api_key)
    @fields = {
        'input_format'=>'image',
        'output_format'=>'png'
    }
    @file_id = 1
    @files = {}
    @raw_data = {}
end

Public Instance Methods

convertFile(file) click to toggle source

Convert a local file.

  • file - The path to a local file to convert. The file must exist and not be empty.

  • Returns - Byte array containing the conversion output.

# File lib/pdfcrowd.rb, line 3178
def convertFile(file)
    if (!(File.file?(file) && !File.zero?(file)))
        raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFile", "image-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) click to toggle source

Convert a local file and write the result to a local file.

  • file - The path to a local file to convert. The file must exist and not be empty.

  • file_path - The output file path. The string must not be empty.

# File lib/pdfcrowd.rb, line 3204
def convertFileToFile(file, file_path)
    if (!(!file_path.nil? && !file_path.empty?))
        raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "convertFileToFile::file_path", "image-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) click to toggle source

Convert a local file and write the result to an output stream.

  • file - The path to a local file to convert. The file must exist and not be empty.

  • out_stream - The output stream that will contain the conversion output.

# File lib/pdfcrowd.rb, line 3191
def convertFileToStream(file, out_stream)
    if (!(File.file?(file) && !File.zero?(file)))
        raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFileToStream::file", "image-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) click to toggle source

Convert raw data.

  • data - The raw content to be converted.

  • Returns - Byte array with the output.

# File lib/pdfcrowd.rb, line 3224
def convertRawData(data)
    @raw_data['file'] = data
    @helper.post(@fields, @files, @raw_data)
end
convertRawDataToFile(data, file_path) click to toggle source

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.

# File lib/pdfcrowd.rb, line 3242
def convertRawDataToFile(data, file_path)
    if (!(!file_path.nil? && !file_path.empty?))
        raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "convertRawDataToFile::file_path", "image-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) click to toggle source

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.

# File lib/pdfcrowd.rb, line 3233
def convertRawDataToStream(data, out_stream)
    @raw_data['file'] = data
    @helper.post(@fields, @files, @raw_data, out_stream)
end
convertStream(in_stream) click to toggle source

Convert the contents of an input stream.

  • in_stream - The input stream with source data.

  • Returns - Byte array containing the conversion output.

# File lib/pdfcrowd.rb, line 3262
def convertStream(in_stream)
    @raw_data['stream'] = in_stream.read
    @helper.post(@fields, @files, @raw_data)
end
convertStreamToFile(in_stream, file_path) click to toggle source

Convert the contents of an input stream and write the result to a local file.

  • in_stream - The input stream with source data.

  • file_path - The output file path. The string must not be empty.

# File lib/pdfcrowd.rb, line 3280
def convertStreamToFile(in_stream, file_path)
    if (!(!file_path.nil? && !file_path.empty?))
        raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "convertStreamToFile::file_path", "image-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) click to toggle source

Convert the contents of an input stream and write the result to an output stream.

  • in_stream - The input stream with source data.

  • out_stream - The output stream that will contain the conversion output.

# File lib/pdfcrowd.rb, line 3271
def convertStreamToStream(in_stream, out_stream)
    @raw_data['stream'] = in_stream.read
    @helper.post(@fields, @files, @raw_data, out_stream)
end
convertUrl(url) click to toggle source

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.

# File lib/pdfcrowd.rb, line 3132
def convertUrl(url)
    unless /(?i)^https?:\/\/.*$/.match(url)
        raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrl", "image-to-image", "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) click to toggle source

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.

# File lib/pdfcrowd.rb, line 3158
def convertUrlToFile(url, file_path)
    if (!(!file_path.nil? && !file_path.empty?))
        raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "convertUrlToFile::file_path", "image-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) click to toggle source

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.

# File lib/pdfcrowd.rb, line 3145
def convertUrlToStream(url, out_stream)
    unless /(?i)^https?:\/\/.*$/.match(url)
        raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrlToStream::url", "image-to-image", "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() click to toggle source

Get the number of credits consumed by the last conversion.

  • Returns - The number of credits.

# File lib/pdfcrowd.rb, line 3353
def getConsumedCreditCount()
    return @helper.getConsumedCreditCount()
end
getDebugLogUrl() click to toggle source

Get the URL of the debug log for the last conversion.

  • Returns - The link to the debug log.

# File lib/pdfcrowd.rb, line 3338
def getDebugLogUrl()
    return @helper.getDebugLogUrl()
end
getJobId() click to toggle source

Get the job id.

  • Returns - The unique job identifier.

# File lib/pdfcrowd.rb, line 3359
def getJobId()
    return @helper.getJobId()
end
getOutputSize() click to toggle source

Get the size of the output in bytes.

  • Returns - The count of bytes.

# File lib/pdfcrowd.rb, line 3365
def getOutputSize()
    return @helper.getOutputSize()
end
getRemainingCreditCount() click to toggle source

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.

# File lib/pdfcrowd.rb, line 3347
def getRemainingCreditCount()
    return @helper.getRemainingCreditCount()
end
getVersion() click to toggle source

Get the version details.

  • Returns - API version, converter version, and client version.

# File lib/pdfcrowd.rb, line 3371
def getVersion()
    return "client " + CLIENT_VERSION + ", API v2, converter " + @helper.getConverterVersion()
end
setConverterVersion(version) click to toggle source

Set the converter version. Different versions may produce different output. Choose which one provides the best output for your case.

  • version - The version identifier. Allowed values are latest, 20.10, 18.10.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 3414
def setConverterVersion(version)
    unless /(?i)^(latest|20.10|18.10)$/.match(version)
        raise Error.new(Pdfcrowd.create_invalid_value_message(version, "setConverterVersion", "image-to-image", "Allowed values are latest, 20.10, 18.10.", "set_converter_version"), 470);
    end
    
    @helper.setConverterVersion(version)
    self
end
setDebugLog(value) click to toggle source

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.

  • value - Set to true to enable the debug logging.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 3331
def setDebugLog(value)
    @fields['debug_log'] = value
    self
end
setHttpProxy(proxy) click to toggle source

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.

  • proxy - The value must have format DOMAIN_OR_IP_ADDRESS:PORT.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 3388
def setHttpProxy(proxy)
    unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(proxy)
        raise Error.new(Pdfcrowd.create_invalid_value_message(proxy, "setHttpProxy", "image-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) click to toggle source

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.

  • proxy - The value must have format DOMAIN_OR_IP_ADDRESS:PORT.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 3401
def setHttpsProxy(proxy)
    unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(proxy)
        raise Error.new(Pdfcrowd.create_invalid_value_message(proxy, "setHttpsProxy", "image-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) click to toggle source

The format of the output file.

  • output_format - Allowed values are png, jpg, gif, tiff, bmp, ico, ppm, pgm, pbm, pnm, psb, pct, ras, tga, sgi, sun, webp.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 3300
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.create_invalid_value_message(output_format, "setOutputFormat", "image-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
setProxy(host, port, user_name, password) click to toggle source

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.

# File lib/pdfcrowd.rb, line 3449
def setProxy(host, port, user_name, password)
    @helper.setProxy(host, port, user_name, password)
    self
end
setResize(resize) click to toggle source

Resize the image.

  • resize - The resize percentage or new image dimensions.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 3313
def setResize(resize)
    @fields['resize'] = resize
    self
end
setRetryCount(count) click to toggle source

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.

  • count - Number of retries wanted.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 3458
def setRetryCount(count)
    @helper.setRetryCount(count)
    self
end
setRotate(rotate) click to toggle source

Rotate the image.

  • rotate - The rotation specified in degrees.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 3322
def setRotate(rotate)
    @fields['rotate'] = rotate
    self
end
setTag(tag) click to toggle source

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.

# File lib/pdfcrowd.rb, line 3379
def setTag(tag)
    @fields['tag'] = tag
    self
end
setUseHttp(value) click to toggle source

Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API. Warning: Using HTTP is insecure as data sent over HTTP is not encrypted. Enable this option only if you know what you are doing.

  • value - Set to true to use HTTP.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 3428
def setUseHttp(value)
    @helper.setUseHttp(value)
    self
end
setUserAgent(agent) click to toggle source

Set a custom user agent HTTP header. It can be useful if you are behind some proxy or firewall.

  • agent - The user agent string.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 3437
def setUserAgent(agent)
    @helper.setUserAgent(agent)
    self
end