Class: Pdfcrowd::HtmlToImageClient
- Inherits:
-
Object
- Object
- Pdfcrowd::HtmlToImageClient
- Defined in:
- lib/pdfcrowd.rb
Overview
Conversion from HTML to image.
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.
-
#convertString(text) ⇒ Object
Convert a string.
-
#convertStringToFile(text, file_path) ⇒ Object
Convert a string and write the output to a file.
-
#convertStringToStream(text, out_stream) ⇒ Object
Convert a string and write the output to an output stream.
-
#convertUrl(url) ⇒ Object
Convert a web page.
-
#convertUrlToFile(url, file_path) ⇒ Object
Convert a web page and write the result to a local file.
-
#convertUrlToStream(url, out_stream) ⇒ Object
Convert a web page 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) ⇒ HtmlToImageClient
constructor
Constructor for the Pdfcrowd API client.
-
#setBlockAds(block_ads) ⇒ Object
Try to block ads.
-
#setClientCertificate(client_certificate) ⇒ Object
A client certificate to authenticate Pdfcrowd converter on your web server.
-
#setClientCertificatePassword(client_certificate_password) ⇒ Object
A password for PKCS12 file with a client certificate if it’s needed.
-
#setCookies(cookies) ⇒ Object
Set cookies that are sent in Pdfcrowd HTTP requests.
-
#setCustomHttpHeader(custom_http_header) ⇒ Object
Set a custom HTTP header that is sent in Pdfcrowd HTTP requests.
-
#setCustomJavascript(custom_javascript) ⇒ Object
Run a custom JavaScript after the document is loaded and ready to print.
-
#setDebugLog(debug_log) ⇒ Object
Turn on the debug logging.
-
#setDefaultEncoding(default_encoding) ⇒ Object
Set the default HTML content text encoding.
-
#setDisableImageLoading(disable_image_loading) ⇒ Object
Do not load images.
-
#setDisableJavascript(disable_javascript) ⇒ Object
Do not execute JavaScript.
-
#setDisableRemoteFonts(disable_remote_fonts) ⇒ Object
Disable loading fonts from remote sources.
-
#setElementToConvert(selectors) ⇒ Object
Convert only the specified element from the main document and its children.
-
#setElementToConvertMode(mode) ⇒ Object
Specify the DOM handling when only a part of the document is converted.
-
#setFailOnAnyUrlError(fail_on_error) ⇒ Object
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.
-
#setFailOnMainUrlError(fail_on_error) ⇒ Object
Abort the conversion if the main URL HTTP status code is greater than or equal to 400.
-
#setHttpAuth(user_name, password) ⇒ Object
Set credentials to access HTTP base authentication protected websites.
-
#setHttpAuthPassword(password) ⇒ Object
Set the HTTP authentication password.
-
#setHttpAuthUserName(user_name) ⇒ Object
Set the HTTP authentication user name.
-
#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.
-
#setJavascriptDelay(javascript_delay) ⇒ Object
Wait the specified number of milliseconds to finish all JavaScript after the document is loaded.
-
#setNoBackground(no_background) ⇒ Object
Do not print the background graphics.
-
#setNoXpdfcrowdHeader(no_xpdfcrowd_header) ⇒ Object
Do not send the X-Pdfcrowd HTTP header in Pdfcrowd HTTP requests.
-
#setOnLoadJavascript(on_load_javascript) ⇒ Object
Run a custom JavaScript right after the document is loaded.
-
#setOutputFormat(output_format) ⇒ Object
The format of the output file.
-
#setProxy(host, port, user_name, password) ⇒ Object
Specifies an HTTP proxy that the API client library will use to connect to the internet.
-
#setRetryCount(retry_count) ⇒ Object
Specifies the number of retries when the 502 HTTP status code is received.
-
#setScaleFactor(scale_factor) ⇒ Object
Set the scaling factor (zoom) for the output image.
-
#setScreenshotHeight(screenshot_height) ⇒ Object
Set the output image height in pixels.
-
#setScreenshotWidth(screenshot_width) ⇒ Object
Set the output image width in pixels.
-
#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.
-
#setUsePrintMedia(use_print_media) ⇒ Object
Use the print version of the page if available (@media print).
-
#setUserAgent(user_agent) ⇒ Object
Set a custom user agent HTTP header.
-
#setVerifySslCertificates(verify_ssl_certificates) ⇒ Object
Do not allow insecure HTTPS connections.
-
#setWaitForElement(selectors) ⇒ Object
Wait for the specified element in a source document.
Constructor Details
#initialize(user_name, api_key) ⇒ HtmlToImageClient
Constructor for the Pdfcrowd API client.
-
user_name
- Your username at Pdfcrowd. -
api_key
- Your API key.
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 |
# File 'lib/pdfcrowd.rb', line 2037 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 |
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). 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.
2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 |
# File 'lib/pdfcrowd.rb', line 2111 def convertFile(file) if (!(File.file?(file) && !File.zero?(file))) raise Error.new(Pdfcrowd.(file, "file", "html-to-image", "The file must exist and not be empty.", "convert_file"), 470); end if (!(File.file?(file) && !File.zero?(file))) raise Error.new(Pdfcrowd.(file, "file", "html-to-image", "The file name must have a valid extension.", "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). 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.
2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 |
# File 'lib/pdfcrowd.rb', line 2145 def convertFileToFile(file, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "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) ⇒ 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). 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.
2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 |
# File 'lib/pdfcrowd.rb', line 2128 def convertFileToStream(file, out_stream) if (!(File.file?(file) && !File.zero?(file))) raise Error.new(Pdfcrowd.(file, "file", "html-to-image", "The file must exist and not be empty.", "convert_file_to_stream"), 470); end if (!(File.file?(file) && !File.zero?(file))) raise Error.new(Pdfcrowd.(file, "file", "html-to-image", "The file name must have a valid extension.", "convert_file_to_stream"), 470); end @files['file'] = file @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertString(text) ⇒ Object
Convert a string.
-
text
- The string content to convert. The string must not be empty. -
Returns - Byte array containing the conversion output.
2165 2166 2167 2168 2169 2170 2171 2172 |
# File 'lib/pdfcrowd.rb', line 2165 def convertString(text) if (!(!text.nil? && !text.empty?)) raise Error.new(Pdfcrowd.(text, "text", "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) ⇒ Object
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.
2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 |
# File 'lib/pdfcrowd.rb', line 2191 def convertStringToFile(text, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "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) ⇒ Object
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.
2178 2179 2180 2181 2182 2183 2184 2185 |
# File 'lib/pdfcrowd.rb', line 2178 def convertStringToStream(text, out_stream) if (!(!text.nil? && !text.empty?)) raise Error.new(Pdfcrowd.(text, "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) ⇒ Object
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.
2065 2066 2067 2068 2069 2070 2071 2072 |
# File 'lib/pdfcrowd.rb', line 2065 def convertUrl(url) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.(url, "url", "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) ⇒ Object
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.
2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 |
# File 'lib/pdfcrowd.rb', line 2091 def convertUrlToFile(url, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "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) ⇒ Object
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.
2078 2079 2080 2081 2082 2083 2084 2085 |
# File 'lib/pdfcrowd.rb', line 2078 def convertUrlToStream(url, out_stream) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.(url, "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 ⇒ Object
Get the number of credits consumed by the last conversion.
-
Returns - The number of credits.
2500 2501 2502 |
# File 'lib/pdfcrowd.rb', line 2500 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.
2485 2486 2487 |
# File 'lib/pdfcrowd.rb', line 2485 def getDebugLogUrl() return @helper.getDebugLogUrl() end |
#getJobId ⇒ Object
Get the job id.
-
Returns - The unique job identifier.
2506 2507 2508 |
# File 'lib/pdfcrowd.rb', line 2506 def getJobId() return @helper.getJobId() end |
#getOutputSize ⇒ Object
Get the size of the output in bytes.
-
Returns - The count of bytes.
2512 2513 2514 |
# File 'lib/pdfcrowd.rb', line 2512 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.
2494 2495 2496 |
# File 'lib/pdfcrowd.rb', line 2494 def getRemainingCreditCount() return @helper.getRemainingCreditCount() end |
#setBlockAds(block_ads) ⇒ Object
Try to block ads. Enabling this option can produce smaller output and speed up the conversion.
-
block_ads
- Set to true to block ads in web pages. -
Returns - The converter object.
2247 2248 2249 2250 |
# File 'lib/pdfcrowd.rb', line 2247 def setBlockAds(block_ads) @fields['block_ads'] = block_ads self end |
#setClientCertificate(client_certificate) ⇒ Object
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.
-
client_certificate
- The file must be in PKCS12 format. The file must exist and not be empty. -
Returns - The converter object.
2555 2556 2557 2558 2559 2560 2561 2562 |
# File 'lib/pdfcrowd.rb', line 2555 def setClientCertificate(client_certificate) if (!(File.file?(client_certificate) && !File.zero?(client_certificate))) raise Error.new(Pdfcrowd.(client_certificate, "client_certificate", "html-to-image", "The file must exist and not be empty.", "set_client_certificate"), 470); end @files['client_certificate'] = client_certificate self end |
#setClientCertificatePassword(client_certificate_password) ⇒ Object
A password for PKCS12 file with a client certificate if it’s needed.
-
client_certificate_password
- -
Returns - The converter object.
2568 2569 2570 2571 |
# File 'lib/pdfcrowd.rb', line 2568 def setClientCertificatePassword(client_certificate_password) @fields['client_certificate_password'] = client_certificate_password self end |
#setCookies(cookies) ⇒ Object
Set cookies that are sent in Pdfcrowd HTTP requests.
-
cookies
- The cookie string. -
Returns - The converter object.
2312 2313 2314 2315 |
# File 'lib/pdfcrowd.rb', line 2312 def setCookies() @fields['cookies'] = self end |
#setCustomHttpHeader(custom_http_header) ⇒ Object
Set a custom HTTP header that is sent in Pdfcrowd HTTP requests.
-
custom_http_header
- A string containing the header name and value separated by a colon. -
Returns - The converter object.
2374 2375 2376 2377 2378 2379 2380 2381 |
# File 'lib/pdfcrowd.rb', line 2374 def setCustomHttpHeader(custom_http_header) unless /^.+:.+$/.match(custom_http_header) raise Error.new(Pdfcrowd.(custom_http_header, "custom_http_header", "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'] = custom_http_header self end |
#setCustomJavascript(custom_javascript) ⇒ Object
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.
-
custom_javascript
- A string containing a JavaScript code. The string must not be empty. -
Returns - The converter object.
2348 2349 2350 2351 2352 2353 2354 2355 |
# File 'lib/pdfcrowd.rb', line 2348 def setCustomJavascript(custom_javascript) if (!(!custom_javascript.nil? && !custom_javascript.empty?)) raise Error.new(Pdfcrowd.(custom_javascript, "custom_javascript", "html-to-image", "The string must not be empty.", "set_custom_javascript"), 470); end @fields['custom_javascript'] = custom_javascript self 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.
2478 2479 2480 2481 |
# File 'lib/pdfcrowd.rb', line 2478 def setDebugLog(debug_log) @fields['debug_log'] = debug_log self end |
#setDefaultEncoding(default_encoding) ⇒ Object
Set the default HTML content text encoding.
-
default_encoding
- The text encoding of the HTML content. -
Returns - The converter object.
2256 2257 2258 2259 |
# File 'lib/pdfcrowd.rb', line 2256 def setDefaultEncoding(default_encoding) @fields['default_encoding'] = default_encoding self end |
#setDisableImageLoading(disable_image_loading) ⇒ Object
Do not load images.
-
disable_image_loading
- Set to true to disable loading of images. -
Returns - The converter object.
2229 2230 2231 2232 |
# File 'lib/pdfcrowd.rb', line 2229 def setDisableImageLoading(disable_image_loading) @fields['disable_image_loading'] = disable_image_loading self end |
#setDisableJavascript(disable_javascript) ⇒ Object
Do not execute JavaScript.
-
disable_javascript
- Set to true to disable JavaScript in web pages. -
Returns - The converter object.
2220 2221 2222 2223 |
# File 'lib/pdfcrowd.rb', line 2220 def setDisableJavascript(disable_javascript) @fields['disable_javascript'] = disable_javascript self end |
#setDisableRemoteFonts(disable_remote_fonts) ⇒ Object
Disable loading fonts from remote sources.
-
disable_remote_fonts
- Set to true disable loading remote fonts. -
Returns - The converter object.
2238 2239 2240 2241 |
# File 'lib/pdfcrowd.rb', line 2238 def setDisableRemoteFonts(disable_remote_fonts) @fields['disable_remote_fonts'] = disable_remote_fonts self end |
#setElementToConvert(selectors) ⇒ Object
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.
2400 2401 2402 2403 2404 2405 2406 2407 |
# File 'lib/pdfcrowd.rb', line 2400 def setElementToConvert(selectors) if (!(!selectors.nil? && !selectors.empty?)) raise Error.new(Pdfcrowd.(selectors, "selectors", "html-to-image", "The string must not be empty.", "set_element_to_convert"), 470); end @fields['element_to_convert'] = selectors self end |
#setElementToConvertMode(mode) ⇒ Object
Specify the DOM handling when only a part of the document is converted.
-
mode
- Allowed values are cut-out, remove-siblings, hide-siblings. -
Returns - The converter object.
2413 2414 2415 2416 2417 2418 2419 2420 |
# File 'lib/pdfcrowd.rb', line 2413 def setElementToConvertMode(mode) unless /(?i)^(cut-out|remove-siblings|hide-siblings)$/.match(mode) raise Error.new(Pdfcrowd.(mode, "mode", "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) ⇒ Object
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.
2339 2340 2341 2342 |
# File 'lib/pdfcrowd.rb', line 2339 def setFailOnAnyUrlError(fail_on_error) @fields['fail_on_any_url_error'] = fail_on_error self end |
#setFailOnMainUrlError(fail_on_error) ⇒ Object
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.
2330 2331 2332 2333 |
# File 'lib/pdfcrowd.rb', line 2330 def setFailOnMainUrlError(fail_on_error) @fields['fail_on_main_url_error'] = fail_on_error self end |
#setHttpAuth(user_name, password) ⇒ Object
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.
2284 2285 2286 2287 2288 |
# File 'lib/pdfcrowd.rb', line 2284 def setHttpAuth(user_name, password) setHttpAuthUserName(user_name) setHttpAuthPassword(password) self end |
#setHttpAuthPassword(password) ⇒ Object
Set the HTTP authentication password.
-
password
- The password. -
Returns - The converter object.
2274 2275 2276 2277 |
# File 'lib/pdfcrowd.rb', line 2274 def setHttpAuthPassword(password) @fields['http_auth_password'] = password self end |
#setHttpAuthUserName(user_name) ⇒ Object
Set the HTTP authentication user name.
-
user_name
- The user name. -
Returns - The converter object.
2265 2266 2267 2268 |
# File 'lib/pdfcrowd.rb', line 2265 def setHttpAuthUserName(user_name) @fields['http_auth_user_name'] = user_name 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.
2529 2530 2531 2532 2533 2534 2535 2536 |
# File 'lib/pdfcrowd.rb', line 2529 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", "html-to-image", "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.
2542 2543 2544 2545 2546 2547 2548 2549 |
# File 'lib/pdfcrowd.rb', line 2542 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", "html-to-image", "The value must have format DOMAIN_OR_IP_ADDRESS:PORT.", "set_https_proxy"), 470); end @fields['https_proxy'] = https_proxy self end |
#setJavascriptDelay(javascript_delay) ⇒ Object
Wait the specified number of milliseconds to finish all JavaScript after the document is loaded. The maximum value is determined by your API license.
-
javascript_delay
- The number of milliseconds to wait. Must be a positive integer number or 0. -
Returns - The converter object.
2387 2388 2389 2390 2391 2392 2393 2394 |
# File 'lib/pdfcrowd.rb', line 2387 def setJavascriptDelay(javascript_delay) if (!(Integer(javascript_delay) >= 0)) raise Error.new(Pdfcrowd.(javascript_delay, "javascript_delay", "html-to-image", "Must be a positive integer number or 0.", "set_javascript_delay"), 470); end @fields['javascript_delay'] = javascript_delay self end |
#setNoBackground(no_background) ⇒ Object
Do not print the background graphics.
-
no_background
- Set to true to disable the background graphics. -
Returns - The converter object.
2211 2212 2213 2214 |
# File 'lib/pdfcrowd.rb', line 2211 def setNoBackground(no_background) @fields['no_background'] = no_background self end |
#setNoXpdfcrowdHeader(no_xpdfcrowd_header) ⇒ Object
Do not send the X-Pdfcrowd HTTP header in Pdfcrowd HTTP requests.
-
no_xpdfcrowd_header
- Set to true to disable sending X-Pdfcrowd HTTP header. -
Returns - The converter object.
2303 2304 2305 2306 |
# File 'lib/pdfcrowd.rb', line 2303 def setNoXpdfcrowdHeader(no_xpdfcrowd_header) @fields['no_xpdfcrowd_header'] = no_xpdfcrowd_header self end |
#setOnLoadJavascript(on_load_javascript) ⇒ Object
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.
-
on_load_javascript
- A string containing a JavaScript code. The string must not be empty. -
Returns - The converter object.
2361 2362 2363 2364 2365 2366 2367 2368 |
# File 'lib/pdfcrowd.rb', line 2361 def setOnLoadJavascript(on_load_javascript) if (!(!on_load_javascript.nil? && !on_load_javascript.empty?)) raise Error.new(Pdfcrowd.(on_load_javascript, "on_load_javascript", "html-to-image", "The string must not be empty.", "set_on_load_javascript"), 470); end @fields['on_load_javascript'] = on_load_javascript self end |
#setOutputFormat(output_format) ⇒ Object
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.
2052 2053 2054 2055 2056 2057 2058 2059 |
# File 'lib/pdfcrowd.rb', line 2052 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, "output_format", "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) ⇒ 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.
2598 2599 2600 2601 |
# File 'lib/pdfcrowd.rb', line 2598 def setProxy(host, port, user_name, password) @helper.setProxy(host, port, user_name, password) 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.
2607 2608 2609 2610 |
# File 'lib/pdfcrowd.rb', line 2607 def setRetryCount(retry_count) @helper.setRetryCount(retry_count) self end |
#setScaleFactor(scale_factor) ⇒ Object
Set the scaling factor (zoom) for the output image.
-
scale_factor
- The percentage value. Must be a positive integer number. -
Returns - The converter object.
2465 2466 2467 2468 2469 2470 2471 2472 |
# File 'lib/pdfcrowd.rb', line 2465 def setScaleFactor(scale_factor) if (!(Integer(scale_factor) > 0)) raise Error.new(Pdfcrowd.(scale_factor, "scale_factor", "html-to-image", "Must be a positive integer number.", "set_scale_factor"), 470); end @fields['scale_factor'] = scale_factor self end |
#setScreenshotHeight(screenshot_height) ⇒ Object
Set the output image height in pixels. If it’s not specified, actual document height is used.
-
screenshot_height
- Must be a positive integer number. -
Returns - The converter object.
2452 2453 2454 2455 2456 2457 2458 2459 |
# File 'lib/pdfcrowd.rb', line 2452 def setScreenshotHeight(screenshot_height) if (!(Integer(screenshot_height) > 0)) raise Error.new(Pdfcrowd.(screenshot_height, "screenshot_height", "html-to-image", "Must be a positive integer number.", "set_screenshot_height"), 470); end @fields['screenshot_height'] = screenshot_height self end |
#setScreenshotWidth(screenshot_width) ⇒ Object
Set the output image width in pixels.
-
screenshot_width
- The value must be in the range 96-7680. -
Returns - The converter object.
2439 2440 2441 2442 2443 2444 2445 2446 |
# File 'lib/pdfcrowd.rb', line 2439 def setScreenshotWidth(screenshot_width) if (!(Integer(screenshot_width) >= 96 && Integer(screenshot_width) <= 7680)) raise Error.new(Pdfcrowd.(screenshot_width, "screenshot_width", "html-to-image", "The value must be in the range 96-7680.", "set_screenshot_width"), 470); end @fields['screenshot_width'] = screenshot_width 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.
2520 2521 2522 2523 |
# File 'lib/pdfcrowd.rb', line 2520 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.
2577 2578 2579 2580 |
# File 'lib/pdfcrowd.rb', line 2577 def setUseHttp(use_http) @helper.setUseHttp(use_http) self end |
#setUsePrintMedia(use_print_media) ⇒ Object
Use the print version of the page if available (@media print).
-
use_print_media
- Set to true to use the print version of the page. -
Returns - The converter object.
2294 2295 2296 2297 |
# File 'lib/pdfcrowd.rb', line 2294 def setUsePrintMedia(use_print_media) @fields['use_print_media'] = use_print_media 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.
2586 2587 2588 2589 |
# File 'lib/pdfcrowd.rb', line 2586 def setUserAgent(user_agent) @helper.setUserAgent(user_agent) self end |
#setVerifySslCertificates(verify_ssl_certificates) ⇒ Object
Do not allow insecure HTTPS connections.
-
verify_ssl_certificates
- Set to true to enable SSL certificate verification. -
Returns - The converter object.
2321 2322 2323 2324 |
# File 'lib/pdfcrowd.rb', line 2321 def setVerifySslCertificates(verify_ssl_certificates) @fields['verify_ssl_certificates'] = verify_ssl_certificates self end |
#setWaitForElement(selectors) ⇒ Object
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.
2426 2427 2428 2429 2430 2431 2432 2433 |
# File 'lib/pdfcrowd.rb', line 2426 def setWaitForElement(selectors) if (!(!selectors.nil? && !selectors.empty?)) raise Error.new(Pdfcrowd.(selectors, "selectors", "html-to-image", "The string must not be empty.", "set_wait_for_element"), 470); end @fields['wait_for_element'] = selectors self end |