class Pdfcrowd::HtmlToImageClient

Conversion from HTML to image.

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 2364
def initialize(user_name, api_key)
    @helper = ConnectionHelper.new(user_name, api_key)
    @fields = {
        'input_format'=>'html',
        '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 can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty. The file name must have a valid extension.

  • Returns - Byte array containing the conversion output.

# File lib/pdfcrowd.rb, line 2438
def convertFile(file)
    if (!(File.file?(file) && !File.zero?(file)))
        raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFile", "html-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 can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty. The file name must have a valid extension.

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

# File lib/pdfcrowd.rb, line 2464
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", "html-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 can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty. The file name must have a valid extension.

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

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

Convert the contents of an input stream.

  • in_stream - The input stream with source data. The stream can contain either HTML code or an archive (.zip, .tar.gz, .tar.bz2).The archive can contain HTML code and its external assets (images, style sheets, javascript).

  • Returns - Byte array containing the conversion output.

# File lib/pdfcrowd.rb, line 2530
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. The stream can contain either HTML code or an archive (.zip, .tar.gz, .tar.bz2).The archive can contain HTML code and its external assets (images, style sheets, javascript).

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

# File lib/pdfcrowd.rb, line 2548
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", "html-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. The stream can contain either HTML code or an archive (.zip, .tar.gz, .tar.bz2).The archive can contain HTML code and its external assets (images, style sheets, javascript).

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

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

Convert a string.

  • text - The string content to convert. The string must not be empty.

  • Returns - Byte array containing the conversion output.

# File lib/pdfcrowd.rb, line 2484
def convertString(text)
    if (!(!text.nil? && !text.empty?))
        raise Error.new(Pdfcrowd.create_invalid_value_message(text, "convertString", "html-to-image", "The string must not be empty.", "convert_string"), 470);
    end
    
    @fields['text'] = text
    @helper.post(@fields, @files, @raw_data)
end
convertStringToFile(text, file_path) click to toggle source

Convert a string and write the output to a file.

  • text - The string content to convert. The string must not be empty.

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

# File lib/pdfcrowd.rb, line 2510
def convertStringToFile(text, file_path)
    if (!(!file_path.nil? && !file_path.empty?))
        raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "convertStringToFile::file_path", "html-to-image", "The string must not be empty.", "convert_string_to_file"), 470);
    end
    
    output_file = open(file_path, "wb")
    begin
        convertStringToStream(text, output_file)
        output_file.close()
    rescue Error => why
        output_file.close()
        FileUtils.rm(file_path)
        raise
    end
end
convertStringToStream(text, out_stream) click to toggle source

Convert a string and write the output to an output stream.

  • text - The string content to convert. The string must not be empty.

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

# File lib/pdfcrowd.rb, line 2497
def convertStringToStream(text, out_stream)
    if (!(!text.nil? && !text.empty?))
        raise Error.new(Pdfcrowd.create_invalid_value_message(text, "convertStringToStream::text", "html-to-image", "The string must not be empty.", "convert_string_to_stream"), 470);
    end
    
    @fields['text'] = text
    @helper.post(@fields, @files, @raw_data, out_stream)
end
convertUrl(url) click to toggle source

Convert a web page.

  • url - The address of the web page to convert. The supported protocols are http:// and https://.

  • Returns - Byte array containing the conversion output.

# File lib/pdfcrowd.rb, line 2392
def convertUrl(url)
    unless /(?i)^https?:\/\/.*$/.match(url)
        raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrl", "html-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 a web page and write the result to a local file.

  • url - The address of the web page 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 2418
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", "html-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 a web page and write the result to an output stream.

  • url - The address of the web page 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 2405
def convertUrlToStream(url, out_stream)
    unless /(?i)^https?:\/\/.*$/.match(url)
        raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrlToStream::url", "html-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 2977
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 2962
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 2983
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 2989
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 2971
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 2995
def getVersion()
    return "client " + CLIENT_VERSION + ", API v2, converter " + @helper.getConverterVersion()
end
setBackgroundColor(color) click to toggle source

The output image background color.

  • color - The value must be in RRGGBB or RRGGBBAA hexadecimal format.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2866
def setBackgroundColor(color)
    unless /^[0-9a-fA-F]{6,8}$/.match(color)
        raise Error.new(Pdfcrowd.create_invalid_value_message(color, "setBackgroundColor", "html-to-image", "The value must be in RRGGBB or RRGGBBAA hexadecimal format.", "set_background_color"), 470);
    end
    
    @fields['background_color'] = color
    self
end
setBlockAds(value) click to toggle source

Try to block ads. Enabling this option can produce smaller output and speed up the conversion.

  • value - Set to true to block ads in web pages.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2635
def setBlockAds(value)
    @fields['block_ads'] = value
    self
end
setClientCertificate(certificate) click to toggle source

A client certificate to authenticate Pdfcrowd converter on your web server. The certificate is used for two-way SSL/TLS authentication and adds extra security.

  • certificate - The file must be in PKCS12 format. The file must exist and not be empty.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 3038
def setClientCertificate(certificate)
    if (!(File.file?(certificate) && !File.zero?(certificate)))
        raise Error.new(Pdfcrowd.create_invalid_value_message(certificate, "setClientCertificate", "html-to-image", "The file must exist and not be empty.", "set_client_certificate"), 470);
    end
    
    @files['client_certificate'] = certificate
    self
end
setClientCertificatePassword(password) click to toggle source

A password for PKCS12 file with a client certificate if it is needed.

  • password -

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 3051
def setClientCertificatePassword(password)
    @fields['client_certificate_password'] = password
    self
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 3060
def setConverterVersion(version)
    unless /(?i)^(latest|20.10|18.10)$/.match(version)
        raise Error.new(Pdfcrowd.create_invalid_value_message(version, "setConverterVersion", "html-to-image", "Allowed values are latest, 20.10, 18.10.", "set_converter_version"), 470);
    end
    
    @helper.setConverterVersion(version)
    self
end
setCookies(cookies) click to toggle source

Set cookies that are sent in Pdfcrowd HTTP requests.

  • cookies - The cookie string.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2691
def setCookies(cookies)
    @fields['cookies'] = cookies
    self
end
setCustomHttpHeader(header) click to toggle source

Set a custom HTTP header that is sent in Pdfcrowd HTTP requests.

  • header - A string containing the header name and value separated by a colon.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2762
def setCustomHttpHeader(header)
    unless /^.+:.+$/.match(header)
        raise Error.new(Pdfcrowd.create_invalid_value_message(header, "setCustomHttpHeader", "html-to-image", "A string containing the header name and value separated by a colon.", "set_custom_http_header"), 470);
    end
    
    @fields['custom_http_header'] = header
    self
end
setCustomJavascript(javascript) click to toggle source

Run a custom JavaScript after the document is loaded and ready to print. The script is intended for post-load DOM manipulation (add/remove elements, update CSS, …). In addition to the standard browser APIs, the custom JavaScript code can use helper functions from our JavaScript library.

  • javascript - A string containing a JavaScript code. The string must not be empty.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2736
def setCustomJavascript(javascript)
    if (!(!javascript.nil? && !javascript.empty?))
        raise Error.new(Pdfcrowd.create_invalid_value_message(javascript, "setCustomJavascript", "html-to-image", "The string must not be empty.", "set_custom_javascript"), 470);
    end
    
    @fields['custom_javascript'] = javascript
    self
end
setDataAutoEscape(value) click to toggle source

Auto escape HTML symbols in the input data before placing them into the output.

  • value - Set to true to turn auto escaping on.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2928
def setDataAutoEscape(value)
    @fields['data_auto_escape'] = value
    self
end
setDataEncoding(encoding) click to toggle source

Set the encoding of the data file set by setDataFile.

  • encoding - The data file encoding.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2910
def setDataEncoding(encoding)
    @fields['data_encoding'] = encoding
    self
end
setDataFile(data_file) click to toggle source

Load the input data for template rendering from the specified file. The data format can be JSON, XML, YAML or CSV.

  • data_file - The file path to a local file containing the input data.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2888
def setDataFile(data_file)
    @files['data_file'] = data_file
    self
end
setDataFormat(data_format) click to toggle source

Specify the input data format.

  • data_format - The data format. Allowed values are auto, json, xml, yaml, csv.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2897
def setDataFormat(data_format)
    unless /(?i)^(auto|json|xml|yaml|csv)$/.match(data_format)
        raise Error.new(Pdfcrowd.create_invalid_value_message(data_format, "setDataFormat", "html-to-image", "Allowed values are auto, json, xml, yaml, csv.", "set_data_format"), 470);
    end
    
    @fields['data_format'] = data_format
    self
end
setDataIgnoreUndefined(value) click to toggle source

Ignore undefined variables in the HTML template. The default mode is strict so any undefined variable causes the conversion to fail. You can use {% if variable is defined %} to check if the variable is defined.

  • value - Set to true to ignore undefined variables.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2919
def setDataIgnoreUndefined(value)
    @fields['data_ignore_undefined'] = value
    self
end
setDataOptions(options) click to toggle source

Set the advanced data options:csv_delimiter - The CSV data delimiter, the default is ,.xml_remove_root - Remove the root XML element from the input data.data_root - The name of the root element inserted into the input data without a root node (e.g. CSV), the default is data.

  • options - Comma separated list of options.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2946
def setDataOptions(options)
    @fields['data_options'] = options
    self
end
setDataString(data_string) click to toggle source

Set the input data for template rendering. The data format can be JSON, XML, YAML or CSV.

  • data_string - The input data string.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2879
def setDataString(data_string)
    @fields['data_string'] = data_string
    self
end
setDataTrimBlocks(value) click to toggle source

Auto trim whitespace around each template command block.

  • value - Set to true to turn auto trimming on.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2937
def setDataTrimBlocks(value)
    @fields['data_trim_blocks'] = value
    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 2955
def setDebugLog(value)
    @fields['debug_log'] = value
    self
end
setDefaultEncoding(encoding) click to toggle source

Set the default HTML content text encoding.

  • encoding - The text encoding of the HTML content.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2644
def setDefaultEncoding(encoding)
    @fields['default_encoding'] = encoding
    self
end
setDisableImageLoading(value) click to toggle source

Do not load images.

  • value - Set to true to disable loading of images.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2604
def setDisableImageLoading(value)
    @fields['disable_image_loading'] = value
    self
end
setDisableJavascript(value) click to toggle source

Do not execute JavaScript.

  • value - Set to true to disable JavaScript in web pages.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2595
def setDisableJavascript(value)
    @fields['disable_javascript'] = value
    self
end
setDisableRemoteFonts(value) click to toggle source

Disable loading fonts from remote sources.

  • value - Set to true disable loading remote fonts.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2613
def setDisableRemoteFonts(value)
    @fields['disable_remote_fonts'] = value
    self
end
setElementToConvert(selectors) click to toggle source

Convert only the specified element from the main document and its children. The element is specified by one or more CSS selectors. If the element is not found, the conversion fails. If multiple elements are found, the first one is used.

  • selectors - One or more CSS selectors separated by commas. The string must not be empty.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2788
def setElementToConvert(selectors)
    if (!(!selectors.nil? && !selectors.empty?))
        raise Error.new(Pdfcrowd.create_invalid_value_message(selectors, "setElementToConvert", "html-to-image", "The string must not be empty.", "set_element_to_convert"), 470);
    end
    
    @fields['element_to_convert'] = selectors
    self
end
setElementToConvertMode(mode) click to toggle source

Specify the DOM handling when only a part of the document is converted. This can affect the CSS rules used.

  • mode - Allowed values are cut-out, remove-siblings, hide-siblings.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2801
def setElementToConvertMode(mode)
    unless /(?i)^(cut-out|remove-siblings|hide-siblings)$/.match(mode)
        raise Error.new(Pdfcrowd.create_invalid_value_message(mode, "setElementToConvertMode", "html-to-image", "Allowed values are cut-out, remove-siblings, hide-siblings.", "set_element_to_convert_mode"), 470);
    end
    
    @fields['element_to_convert_mode'] = mode
    self
end
setFailOnAnyUrlError(fail_on_error) click to toggle source

Abort the conversion if any of the sub-request HTTP status code is greater than or equal to 400 or if some sub-requests are still pending. See details in a debug log.

  • fail_on_error - Set to true to abort the conversion.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2718
def setFailOnAnyUrlError(fail_on_error)
    @fields['fail_on_any_url_error'] = fail_on_error
    self
end
setFailOnMainUrlError(fail_on_error) click to toggle source

Abort the conversion if the main URL HTTP status code is greater than or equal to 400.

  • fail_on_error - Set to true to abort the conversion.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2709
def setFailOnMainUrlError(fail_on_error)
    @fields['fail_on_main_url_error'] = fail_on_error
    self
end
setHttpAuth(user_name, password) click to toggle source

Set credentials to access HTTP base authentication protected websites.

  • user_name - Set the HTTP authentication user name.

  • password - Set the HTTP authentication password.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2681
def setHttpAuth(user_name, password)
    setHttpAuthUserName(user_name)
    setHttpAuthPassword(password)
    self
end
setHttpAuthPassword(password) click to toggle source

Set the HTTP authentication password.

  • password - The password.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2671
def setHttpAuthPassword(password)
    @fields['http_auth_password'] = password
    self
end
setHttpAuthUserName(user_name) click to toggle source

Set the HTTP authentication user name.

  • user_name - The user name.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2662
def setHttpAuthUserName(user_name)
    @fields['http_auth_user_name'] = user_name
    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 3012
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", "html-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 3025
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", "html-to-image", "The value must have format DOMAIN_OR_IP_ADDRESS:PORT.", "set_https_proxy"), 470);
    end
    
    @fields['https_proxy'] = proxy
    self
end
setJavascriptDelay(delay) click to toggle source

Wait the specified number of milliseconds to finish all JavaScript after the document is loaded. Your API license defines the maximum wait time by “Max Delay” parameter.

  • delay - The number of milliseconds to wait. Must be a positive integer number or 0.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2775
def setJavascriptDelay(delay)
    if (!(Integer(delay) >= 0))
        raise Error.new(Pdfcrowd.create_invalid_value_message(delay, "setJavascriptDelay", "html-to-image", "Must be a positive integer number or 0.", "set_javascript_delay"), 470);
    end
    
    @fields['javascript_delay'] = delay
    self
end
setLoadIframes(iframes) click to toggle source

Specifies how iframes are handled.

  • iframes - Allowed values are all, same-origin, none.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2622
def setLoadIframes(iframes)
    unless /(?i)^(all|same-origin|none)$/.match(iframes)
        raise Error.new(Pdfcrowd.create_invalid_value_message(iframes, "setLoadIframes", "html-to-image", "Allowed values are all, same-origin, none.", "set_load_iframes"), 470);
    end
    
    @fields['load_iframes'] = iframes
    self
end
setLocale(locale) click to toggle source

Set the locale for the conversion. This may affect the output format of dates, times and numbers.

  • locale - The locale code according to ISO 639.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2653
def setLocale(locale)
    @fields['locale'] = locale
    self
end
setNoBackground(value) click to toggle source

Do not print the background graphics.

  • value - Set to true to disable the background graphics.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2586
def setNoBackground(value)
    @fields['no_background'] = value
    self
end
setNoXpdfcrowdHeader(value) click to toggle source

Do not send the X-Pdfcrowd HTTP header in Pdfcrowd HTTP requests.

  • value - Set to true to disable sending X-Pdfcrowd HTTP header.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2727
def setNoXpdfcrowdHeader(value)
    @fields['no_xpdfcrowd_header'] = value
    self
end
setOnLoadJavascript(javascript) click to toggle source

Run a custom JavaScript right after the document is loaded. The script is intended for early DOM manipulation (add/remove elements, update CSS, …). In addition to the standard browser APIs, the custom JavaScript code can use helper functions from our JavaScript library.

  • javascript - A string containing a JavaScript code. The string must not be empty.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2749
def setOnLoadJavascript(javascript)
    if (!(!javascript.nil? && !javascript.empty?))
        raise Error.new(Pdfcrowd.create_invalid_value_message(javascript, "setOnLoadJavascript", "html-to-image", "The string must not be empty.", "set_on_load_javascript"), 470);
    end
    
    @fields['on_load_javascript'] = javascript
    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 2379
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", "html-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 3095
def setProxy(host, port, user_name, password)
    @helper.setProxy(host, port, user_name, password)
    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 3104
def setRetryCount(count)
    @helper.setRetryCount(count)
    self
end
setScaleFactor(factor) click to toggle source

Set the scaling factor (zoom) for the output image.

  • factor - The percentage value. Must be a positive integer number.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2853
def setScaleFactor(factor)
    if (!(Integer(factor) > 0))
        raise Error.new(Pdfcrowd.create_invalid_value_message(factor, "setScaleFactor", "html-to-image", "Must be a positive integer number.", "set_scale_factor"), 470);
    end
    
    @fields['scale_factor'] = factor
    self
end
setScreenshotHeight(height) click to toggle source

Set the output image height in pixels. If it is not specified, actual document height is used.

  • height - Must be a positive integer number.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2840
def setScreenshotHeight(height)
    if (!(Integer(height) > 0))
        raise Error.new(Pdfcrowd.create_invalid_value_message(height, "setScreenshotHeight", "html-to-image", "Must be a positive integer number.", "set_screenshot_height"), 470);
    end
    
    @fields['screenshot_height'] = height
    self
end
setScreenshotWidth(width) click to toggle source

Set the output image width in pixels.

  • width - The value must be in the range 96-65000.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2827
def setScreenshotWidth(width)
    if (!(Integer(width) >= 96 && Integer(width) <= 65000))
        raise Error.new(Pdfcrowd.create_invalid_value_message(width, "setScreenshotWidth", "html-to-image", "The value must be in the range 96-65000.", "set_screenshot_width"), 470);
    end
    
    @fields['screenshot_width'] = width
    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 3003
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 3074
def setUseHttp(value)
    @helper.setUseHttp(value)
    self
end
setUsePrintMedia(value) click to toggle source

Use the print version of the page if available (@media print).

  • value - Set to true to use the print version of the page.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2577
def setUsePrintMedia(value)
    @fields['use_print_media'] = 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 3083
def setUserAgent(agent)
    @helper.setUserAgent(agent)
    self
end
setVerifySslCertificates(value) click to toggle source

Do not allow insecure HTTPS connections.

  • value - Set to true to enable SSL certificate verification.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2700
def setVerifySslCertificates(value)
    @fields['verify_ssl_certificates'] = value
    self
end
setWaitForElement(selectors) click to toggle source

Wait for the specified element in a source document. The element is specified by one or more CSS selectors. The element is searched for in the main document and all iframes. If the element is not found, the conversion fails. Your API license defines the maximum wait time by “Max Delay” parameter.

  • selectors - One or more CSS selectors separated by commas. The string must not be empty.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2814
def setWaitForElement(selectors)
    if (!(!selectors.nil? && !selectors.empty?))
        raise Error.new(Pdfcrowd.create_invalid_value_message(selectors, "setWaitForElement", "html-to-image", "The string must not be empty.", "set_wait_for_element"), 470);
    end
    
    @fields['wait_for_element'] = selectors
    self
end
setZipMainFilename(filename) click to toggle source

Set the file name of the main HTML document stored in the input archive. If not specified, the first HTML file in the archive is used for conversion. Use this method if the input archive contains multiple HTML documents.

  • filename - The file name.

  • Returns - The converter object.

# File lib/pdfcrowd.rb, line 2568
def setZipMainFilename(filename)
    @fields['zip_main_filename'] = filename
    self
end