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.
-
#convertStream(in_stream) ⇒ Object
Convert the contents of an input stream.
-
#convertStreamToFile(in_stream, file_path) ⇒ Object
Convert the contents of an input stream and write the result to a local file.
-
#convertStreamToStream(in_stream, out_stream) ⇒ Object
Convert the contents of an input stream 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.
-
#getVersion ⇒ Object
Get the version details.
-
#initialize(user_name, api_key) ⇒ HtmlToImageClient
constructor
Constructor for the PDFCrowd API client.
-
#setAutoDetectElementToConvert(value) ⇒ Object
The main HTML element for conversion is detected automatically.
-
#setBackgroundColor(color) ⇒ Object
The output image background color.
-
#setBlockAds(value) ⇒ Object
Try to block ads.
-
#setClientCertificate(certificate) ⇒ Object
A client certificate to authenticate the converter on your web server.
-
#setClientCertificatePassword(password) ⇒ Object
A password for PKCS12 file with a client certificate if it is needed.
-
#setClientUserAgent(agent) ⇒ Object
Specifies the User-Agent HTTP header that the client library will use when interacting with the API.
-
#setConverterUserAgent(agent) ⇒ Object
Specifies the User-Agent HTTP header that will be used by the converter when a request is made to the converted web page.
-
#setConverterVersion(version) ⇒ Object
Set the converter version.
-
#setCookies(cookies) ⇒ Object
Set HTTP cookies to be included in all requests made by the converter.
-
#setCustomCss(css) ⇒ Object
Apply custom CSS to the input HTML document.
-
#setCustomHttpHeader(header) ⇒ Object
Set a custom HTTP header to be included in all requests made by the converter.
-
#setCustomJavascript(javascript) ⇒ Object
Run a custom JavaScript after the document is loaded and ready to print.
-
#setDataAutoEscape(value) ⇒ Object
Auto escape HTML symbols in the input data before placing them into the output.
-
#setDataEncoding(encoding) ⇒ Object
Set the encoding of the data file set by setDataFile.
-
#setDataFile(data_file) ⇒ Object
Load the input data for template rendering from the specified file.
-
#setDataFormat(data_format) ⇒ Object
Specify the input data format.
-
#setDataIgnoreUndefined(value) ⇒ Object
Ignore undefined variables in the HTML template.
-
#setDataOptions(options) ⇒ Object
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.
-
#setDataString(data_string) ⇒ Object
Set the input data for template rendering.
-
#setDataTrimBlocks(value) ⇒ Object
Auto trim whitespace around each template command block.
-
#setDebugLog(value) ⇒ Object
Turn on the debug logging.
-
#setDefaultEncoding(encoding) ⇒ Object
Set the default HTML content text encoding.
-
#setDisableImageLoading(value) ⇒ Object
Do not load images.
-
#setDisableJavascript(value) ⇒ Object
Do not execute JavaScript.
-
#setDisableRemoteFonts(value) ⇒ 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
- #setHttpAuthUserName(user_name) ⇒ Object
-
#setHttpProxy(proxy) ⇒ Object
A proxy server used by the conversion process for accessing the source URLs with HTTP scheme.
-
#setHttpsProxy(proxy) ⇒ Object
A proxy server used by the conversion process for accessing the source URLs with HTTPS scheme.
-
#setJavascriptDelay(delay) ⇒ Object
Wait the specified number of milliseconds to finish all JavaScript after the document is loaded.
-
#setLoadIframes(iframes) ⇒ Object
Specifies how iframes are handled.
-
#setLocale(locale) ⇒ Object
Set the locale for the conversion.
-
#setMaxLoadingTime(max_time) ⇒ Object
Set the maximum time to load the page and its resources.
-
#setNoBackground(value) ⇒ Object
Do not print the background graphics.
-
#setNoXpdfcrowdHeader(value) ⇒ Object
Do not send the X-Pdfcrowd HTTP header in PDFCrowd HTTP requests.
-
#setOnLoadJavascript(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.
-
#setReadabilityEnhancements(enhancements) ⇒ Object
The input HTML is automatically enhanced to improve the readability.
-
#setRetryCount(count) ⇒ Object
Specifies the number of automatic retries when the 502 or 503 HTTP status code is received.
-
#setScaleFactor(factor) ⇒ Object
Set the scaling factor (zoom) for the output image.
-
#setScreenshotHeight(height) ⇒ Object
Set the output image height in pixels.
-
#setScreenshotWidth(width) ⇒ Object
Set the output image width in pixels.
- #setSubprocessReferrer(referrer) ⇒ Object
-
#setTag(tag) ⇒ Object
Tag the conversion with a custom value.
-
#setUseHttp(value) ⇒ Object
Specify whether to use HTTP or HTTPS when connecting to the PDFCrowd API.
-
#setUseMobileUserAgent(value) ⇒ Object
Use a mobile user agent.
-
#setUsePrintMedia(value) ⇒ Object
Use the print version of the page if available (@media print).
-
#setUserAgent(agent) ⇒ Object
Set a custom user agent HTTP header.
-
#setVerifySslCertificates(value) ⇒ Object
Do not allow insecure HTTPS connections.
-
#setWaitForElement(selectors) ⇒ Object
Wait for the specified element in a source document.
-
#setZipMainFilename(filename) ⇒ Object
Set the file name of the main HTML document stored in the input archive.
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.
2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 |
# File 'lib/pdfcrowd.rb', line 2558 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.
2632 2633 2634 2635 2636 2637 2638 2639 |
# File 'lib/pdfcrowd.rb', line 2632 def convertFile(file) if (!(File.file?(file) && !File.zero?(file))) raise Error.new(Pdfcrowd.(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) ⇒ 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.
2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 |
# File 'lib/pdfcrowd.rb', line 2658 def convertFileToFile(file, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(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) ⇒ 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.
2645 2646 2647 2648 2649 2650 2651 2652 |
# File 'lib/pdfcrowd.rb', line 2645 def convertFileToStream(file, out_stream) if (!(File.file?(file) && !File.zero?(file))) raise Error.new(Pdfcrowd.(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) ⇒ Object
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.
2724 2725 2726 2727 |
# File 'lib/pdfcrowd.rb', line 2724 def convertStream(in_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data) end |
#convertStreamToFile(in_stream, file_path) ⇒ Object
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.
2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 |
# File 'lib/pdfcrowd.rb', line 2742 def convertStreamToFile(in_stream, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(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) ⇒ Object
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.
2733 2734 2735 2736 |
# File 'lib/pdfcrowd.rb', line 2733 def convertStreamToStream(in_stream, out_stream) @raw_data['stream'] = in_stream.read @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.
2678 2679 2680 2681 2682 2683 2684 2685 |
# File 'lib/pdfcrowd.rb', line 2678 def convertString(text) if (!(!text.nil? && !text.empty?)) raise Error.new(Pdfcrowd.(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) ⇒ 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.
2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 |
# File 'lib/pdfcrowd.rb', line 2704 def convertStringToFile(text, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(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) ⇒ 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.
2691 2692 2693 2694 2695 2696 2697 2698 |
# File 'lib/pdfcrowd.rb', line 2691 def convertStringToStream(text, out_stream) if (!(!text.nil? && !text.empty?)) raise Error.new(Pdfcrowd.(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) ⇒ Object
Convert a web page.
-
url
- The address of the web page to convert. Supported protocols are http:// and https://. -
Returns - Byte array containing the conversion output.
2586 2587 2588 2589 2590 2591 2592 2593 |
# File 'lib/pdfcrowd.rb', line 2586 def convertUrl(url) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.(url, "convertUrl", "html-to-image", "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. Supported protocols are http:// and https://. -
file_path
- The output file path. The string must not be empty.
2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 |
# File 'lib/pdfcrowd.rb', line 2612 def convertUrlToFile(url, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(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) ⇒ Object
Convert a web page and write the result to an output stream.
-
url
- The address of the web page to convert. Supported protocols are http:// and https://. -
out_stream
- The output stream that will contain the conversion output.
2599 2600 2601 2602 2603 2604 2605 2606 |
# File 'lib/pdfcrowd.rb', line 2599 def convertUrlToStream(url, out_stream) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.(url, "convertUrlToStream::url", "html-to-image", "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.
3209 3210 3211 |
# File 'lib/pdfcrowd.rb', line 3209 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.
3194 3195 3196 |
# File 'lib/pdfcrowd.rb', line 3194 def getDebugLogUrl() return @helper.getDebugLogUrl() end |
#getJobId ⇒ Object
Get the job id.
-
Returns - The unique job identifier.
3215 3216 3217 |
# File 'lib/pdfcrowd.rb', line 3215 def getJobId() return @helper.getJobId() end |
#getOutputSize ⇒ Object
Get the size of the output in bytes.
-
Returns - The count of bytes.
3221 3222 3223 |
# File 'lib/pdfcrowd.rb', line 3221 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 convertXtoY 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.
3203 3204 3205 |
# File 'lib/pdfcrowd.rb', line 3203 def getRemainingCreditCount() return @helper.getRemainingCreditCount() end |
#getVersion ⇒ Object
Get the version details.
-
Returns - API version, converter version, and client version.
3227 3228 3229 |
# File 'lib/pdfcrowd.rb', line 3227 def getVersion() return "client " + CLIENT_VERSION + ", API v2, converter " + @helper.getConverterVersion() end |
#setAutoDetectElementToConvert(value) ⇒ Object
The main HTML element for conversion is detected automatically.
-
value
- Set to true to detect the main element. -
Returns - The converter object.
3089 3090 3091 3092 |
# File 'lib/pdfcrowd.rb', line 3089 def setAutoDetectElementToConvert(value) @fields['auto_detect_element_to_convert'] = value self end |
#setBackgroundColor(color) ⇒ Object
The output image background color.
-
color
- The value must be in RRGGBB or RRGGBBAA hexadecimal format. -
Returns - The converter object.
2810 2811 2812 2813 2814 2815 2816 2817 |
# File 'lib/pdfcrowd.rb', line 2810 def setBackgroundColor(color) unless /^[0-9a-fA-F]{6,8}$/.match(color) raise Error.new(Pdfcrowd.(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) ⇒ Object
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.
2890 2891 2892 2893 |
# File 'lib/pdfcrowd.rb', line 2890 def setBlockAds(value) @fields['block_ads'] = value self end |
#setClientCertificate(certificate) ⇒ Object
A client certificate to authenticate the 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.
3270 3271 3272 3273 3274 3275 3276 3277 |
# File 'lib/pdfcrowd.rb', line 3270 def setClientCertificate(certificate) if (!(File.file?(certificate) && !File.zero?(certificate))) raise Error.new(Pdfcrowd.(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) ⇒ Object
A password for PKCS12 file with a client certificate if it is needed.
-
password
- -
Returns - The converter object.
3283 3284 3285 3286 |
# File 'lib/pdfcrowd.rb', line 3283 def setClientCertificatePassword(password) @fields['client_certificate_password'] = password self end |
#setClientUserAgent(agent) ⇒ Object
Specifies the User-Agent HTTP header that the client library will use when interacting with the API.
-
agent
- The user agent string. -
Returns - The converter object.
3343 3344 3345 3346 |
# File 'lib/pdfcrowd.rb', line 3343 def setClientUserAgent(agent) @helper.setUserAgent(agent) self end |
#setConverterUserAgent(agent) ⇒ Object
Specifies the User-Agent HTTP header that will be used by the converter when a request is made to the converted web page.
-
agent
- The user agent. -
Returns - The converter object.
3311 3312 3313 3314 |
# File 'lib/pdfcrowd.rb', line 3311 def setConverterUserAgent(agent) @fields['converter_user_agent'] = agent self end |
#setConverterVersion(version) ⇒ Object
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 24.04, 20.10, 18.10, latest. -
Returns - The converter object.
3320 3321 3322 3323 3324 3325 3326 3327 |
# File 'lib/pdfcrowd.rb', line 3320 def setConverterVersion(version) unless /(?i)^(24.04|20.10|18.10|latest)$/.match(version) raise Error.new(Pdfcrowd.(version, "setConverterVersion", "html-to-image", "Allowed values are 24.04, 20.10, 18.10, latest.", "set_converter_version"), 470); end @helper.setConverterVersion(version) self end |
#setCookies(cookies) ⇒ Object
Set HTTP cookies to be included in all requests made by the converter.
-
cookies
- The cookie string. -
Returns - The converter object.
2940 2941 2942 2943 |
# File 'lib/pdfcrowd.rb', line 2940 def setCookies() @fields['cookies'] = self end |
#setCustomCss(css) ⇒ Object
Apply custom CSS to the input HTML document. It allows you to modify the visual appearance and layout of your HTML content dynamically. Tip: Using !important in custom CSS provides a way to prioritize and override conflicting styles.
-
css
- A string containing valid CSS. The string must not be empty. -
Returns - The converter object.
2985 2986 2987 2988 2989 2990 2991 2992 |
# File 'lib/pdfcrowd.rb', line 2985 def setCustomCss(css) if (!(!css.nil? && !css.empty?)) raise Error.new(Pdfcrowd.(css, "setCustomCss", "html-to-image", "The string must not be empty.", "set_custom_css"), 470); end @fields['custom_css'] = css self end |
#setCustomHttpHeader(header) ⇒ Object
Set a custom HTTP header to be included in all requests made by the converter.
-
header
- A string containing the header name and value separated by a colon. -
Returns - The converter object.
3024 3025 3026 3027 3028 3029 3030 3031 |
# File 'lib/pdfcrowd.rb', line 3024 def setCustomHttpHeader(header) unless /^.+:.+$/.match(header) raise Error.new(Pdfcrowd.(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) ⇒ 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.
-
javascript
- A string containing a JavaScript code. The string must not be empty. -
Returns - The converter object.
2998 2999 3000 3001 3002 3003 3004 3005 |
# File 'lib/pdfcrowd.rb', line 2998 def setCustomJavascript(javascript) if (!(!javascript.nil? && !javascript.empty?)) raise Error.new(Pdfcrowd.(javascript, "setCustomJavascript", "html-to-image", "The string must not be empty.", "set_custom_javascript"), 470); end @fields['custom_javascript'] = javascript self end |
#setDataAutoEscape(value) ⇒ Object
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.
3160 3161 3162 3163 |
# File 'lib/pdfcrowd.rb', line 3160 def setDataAutoEscape(value) @fields['data_auto_escape'] = value self end |
#setDataEncoding(encoding) ⇒ Object
Set the encoding of the data file set by setDataFile.
-
encoding
- The data file encoding. -
Returns - The converter object.
3142 3143 3144 3145 |
# File 'lib/pdfcrowd.rb', line 3142 def setDataEncoding(encoding) @fields['data_encoding'] = encoding self end |
#setDataFile(data_file) ⇒ Object
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.
3120 3121 3122 3123 |
# File 'lib/pdfcrowd.rb', line 3120 def setDataFile(data_file) @files['data_file'] = data_file self end |
#setDataFormat(data_format) ⇒ Object
Specify the input data format.
-
data_format
- The data format. Allowed values are auto, json, xml, yaml, csv. -
Returns - The converter object.
3129 3130 3131 3132 3133 3134 3135 3136 |
# File 'lib/pdfcrowd.rb', line 3129 def setDataFormat(data_format) unless /(?i)^(auto|json|xml|yaml|csv)$/.match(data_format) raise Error.new(Pdfcrowd.(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) ⇒ Object
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.
3151 3152 3153 3154 |
# File 'lib/pdfcrowd.rb', line 3151 def setDataIgnoreUndefined(value) @fields['data_ignore_undefined'] = value self end |
#setDataOptions(options) ⇒ Object
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.
3178 3179 3180 3181 |
# File 'lib/pdfcrowd.rb', line 3178 def setDataOptions() @fields['data_options'] = self end |
#setDataString(data_string) ⇒ Object
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.
3111 3112 3113 3114 |
# File 'lib/pdfcrowd.rb', line 3111 def setDataString(data_string) @fields['data_string'] = data_string self end |
#setDataTrimBlocks(value) ⇒ Object
Auto trim whitespace around each template command block.
-
value
- Set to true to turn auto trimming on. -
Returns - The converter object.
3169 3170 3171 3172 |
# File 'lib/pdfcrowd.rb', line 3169 def setDataTrimBlocks(value) @fields['data_trim_blocks'] = value self end |
#setDebugLog(value) ⇒ 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.
-
value
- Set to true to enable the debug logging. -
Returns - The converter object.
3187 3188 3189 3190 |
# File 'lib/pdfcrowd.rb', line 3187 def setDebugLog(value) @fields['debug_log'] = value self end |
#setDefaultEncoding(encoding) ⇒ Object
Set the default HTML content text encoding.
-
encoding
- The text encoding of the HTML content. -
Returns - The converter object.
2899 2900 2901 2902 |
# File 'lib/pdfcrowd.rb', line 2899 def setDefaultEncoding(encoding) @fields['default_encoding'] = encoding self end |
#setDisableImageLoading(value) ⇒ Object
Do not load images.
-
value
- Set to true to disable loading of images. -
Returns - The converter object.
2850 2851 2852 2853 |
# File 'lib/pdfcrowd.rb', line 2850 def setDisableImageLoading(value) @fields['disable_image_loading'] = value self end |
#setDisableJavascript(value) ⇒ Object
Do not execute JavaScript.
-
value
- Set to true to disable JavaScript in web pages. -
Returns - The converter object.
2841 2842 2843 2844 |
# File 'lib/pdfcrowd.rb', line 2841 def setDisableJavascript(value) @fields['disable_javascript'] = value self end |
#setDisableRemoteFonts(value) ⇒ Object
Disable loading fonts from remote sources.
-
value
- Set to true disable loading remote fonts. -
Returns - The converter object.
2859 2860 2861 2862 |
# File 'lib/pdfcrowd.rb', line 2859 def setDisableRemoteFonts(value) @fields['disable_remote_fonts'] = value 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.
3050 3051 3052 3053 3054 3055 3056 3057 |
# File 'lib/pdfcrowd.rb', line 3050 def setElementToConvert(selectors) if (!(!selectors.nil? && !selectors.empty?)) raise Error.new(Pdfcrowd.(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) ⇒ Object
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.
3063 3064 3065 3066 3067 3068 3069 3070 |
# File 'lib/pdfcrowd.rb', line 3063 def setElementToConvertMode(mode) unless /(?i)^(cut-out|remove-siblings|hide-siblings)$/.match(mode) raise Error.new(Pdfcrowd.(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) ⇒ 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.
2967 2968 2969 2970 |
# File 'lib/pdfcrowd.rb', line 2967 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.
2958 2959 2960 2961 |
# File 'lib/pdfcrowd.rb', line 2958 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.
2930 2931 2932 2933 2934 |
# File 'lib/pdfcrowd.rb', line 2930 def setHttpAuth(user_name, password) setHttpAuthUserName(user_name) setHttpAuthPassword(password) self end |
#setHttpAuthPassword(password) ⇒ Object
2920 2921 2922 2923 |
# File 'lib/pdfcrowd.rb', line 2920 def setHttpAuthPassword(password) @fields['http_auth_password'] = password self end |
#setHttpAuthUserName(user_name) ⇒ Object
2914 2915 2916 2917 |
# File 'lib/pdfcrowd.rb', line 2914 def setHttpAuthUserName(user_name) @fields['http_auth_user_name'] = user_name self end |
#setHttpProxy(proxy) ⇒ Object
A proxy server used by the 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.
3244 3245 3246 3247 3248 3249 3250 3251 |
# File 'lib/pdfcrowd.rb', line 3244 def setHttpProxy(proxy) unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(proxy) raise Error.new(Pdfcrowd.(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) ⇒ Object
A proxy server used by the 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.
3257 3258 3259 3260 3261 3262 3263 3264 |
# File 'lib/pdfcrowd.rb', line 3257 def setHttpsProxy(proxy) unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(proxy) raise Error.new(Pdfcrowd.(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) ⇒ Object
Wait the specified number of milliseconds to finish all JavaScript after the document is loaded. Your license defines the maximum wait time by “Max Delay” parameter.
-
delay
- The number of milliseconds to wait. Must be a positive integer or 0. -
Returns - The converter object.
3037 3038 3039 3040 3041 3042 3043 3044 |
# File 'lib/pdfcrowd.rb', line 3037 def setJavascriptDelay(delay) if (!(Integer(delay) >= 0)) raise Error.new(Pdfcrowd.(delay, "setJavascriptDelay", "html-to-image", "Must be a positive integer or 0.", "set_javascript_delay"), 470); end @fields['javascript_delay'] = delay self end |
#setLoadIframes(iframes) ⇒ Object
Specifies how iframes are handled.
-
iframes
- Allowed values are all, same-origin, none. -
Returns - The converter object.
2877 2878 2879 2880 2881 2882 2883 2884 |
# File 'lib/pdfcrowd.rb', line 2877 def setLoadIframes(iframes) unless /(?i)^(all|same-origin|none)$/.match(iframes) raise Error.new(Pdfcrowd.(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) ⇒ Object
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.
2908 2909 2910 2911 |
# File 'lib/pdfcrowd.rb', line 2908 def setLocale(locale) @fields['locale'] = locale self end |
#setMaxLoadingTime(max_time) ⇒ Object
Set the maximum time to load the page and its resources. After this time, all requests will be considered successful. This can be useful to ensure that the conversion does not timeout. Use this method if there is no other way to fix page loading.
-
max_time
- The number of seconds to wait. The accepted range is 10-30. -
Returns - The converter object.
3292 3293 3294 3295 3296 3297 3298 3299 |
# File 'lib/pdfcrowd.rb', line 3292 def setMaxLoadingTime(max_time) if (!(Integer(max_time) >= 10 && Integer(max_time) <= 30)) raise Error.new(Pdfcrowd.(max_time, "setMaxLoadingTime", "html-to-image", "The accepted range is 10-30.", "set_max_loading_time"), 470); end @fields['max_loading_time'] = max_time self end |
#setNoBackground(value) ⇒ Object
Do not print the background graphics.
-
value
- Set to true to disable the background graphics. -
Returns - The converter object.
2832 2833 2834 2835 |
# File 'lib/pdfcrowd.rb', line 2832 def setNoBackground(value) @fields['no_background'] = value self end |
#setNoXpdfcrowdHeader(value) ⇒ Object
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.
2976 2977 2978 2979 |
# File 'lib/pdfcrowd.rb', line 2976 def setNoXpdfcrowdHeader(value) @fields['no_xpdfcrowd_header'] = value self end |
#setOnLoadJavascript(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.
-
javascript
- A string containing a JavaScript code. The string must not be empty. -
Returns - The converter object.
3011 3012 3013 3014 3015 3016 3017 3018 |
# File 'lib/pdfcrowd.rb', line 3011 def setOnLoadJavascript(javascript) if (!(!javascript.nil? && !javascript.empty?)) raise Error.new(Pdfcrowd.(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) ⇒ 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.
2573 2574 2575 2576 2577 2578 2579 2580 |
# File 'lib/pdfcrowd.rb', line 2573 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, "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) ⇒ 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.
3364 3365 3366 3367 |
# File 'lib/pdfcrowd.rb', line 3364 def setProxy(host, port, user_name, password) @helper.setProxy(host, port, user_name, password) self end |
#setReadabilityEnhancements(enhancements) ⇒ Object
The input HTML is automatically enhanced to improve the readability.
-
enhancements
- Allowed values are none, readability-v1, readability-v2, readability-v3, readability-v4. -
Returns - The converter object.
3098 3099 3100 3101 3102 3103 3104 3105 |
# File 'lib/pdfcrowd.rb', line 3098 def setReadabilityEnhancements(enhancements) unless /(?i)^(none|readability-v1|readability-v2|readability-v3|readability-v4)$/.match(enhancements) raise Error.new(Pdfcrowd.(enhancements, "setReadabilityEnhancements", "html-to-image", "Allowed values are none, readability-v1, readability-v2, readability-v3, readability-v4.", "set_readability_enhancements"), 470); end @fields['readability_enhancements'] = enhancements self end |
#setRetryCount(count) ⇒ Object
Specifies the number of automatic retries when the 502 or 503 HTTP status code is received. The status code indicates a temporary network issue. This feature can be disabled by setting to 0.
-
count
- Number of retries. -
Returns - The converter object.
3373 3374 3375 3376 |
# File 'lib/pdfcrowd.rb', line 3373 def setRetryCount(count) @helper.setRetryCount(count) self end |
#setScaleFactor(factor) ⇒ Object
Set the scaling factor (zoom) for the output image.
-
factor
- The percentage value. Must be a positive integer. -
Returns - The converter object.
2797 2798 2799 2800 2801 2802 2803 2804 |
# File 'lib/pdfcrowd.rb', line 2797 def setScaleFactor(factor) if (!(Integer(factor) > 0)) raise Error.new(Pdfcrowd.(factor, "setScaleFactor", "html-to-image", "Must be a positive integer.", "set_scale_factor"), 470); end @fields['scale_factor'] = factor self end |
#setScreenshotHeight(height) ⇒ Object
Set the output image height in pixels. If it is not specified, actual document height is used.
-
height
- Must be a positive integer. -
Returns - The converter object.
2784 2785 2786 2787 2788 2789 2790 2791 |
# File 'lib/pdfcrowd.rb', line 2784 def setScreenshotHeight(height) if (!(Integer(height) > 0)) raise Error.new(Pdfcrowd.(height, "setScreenshotHeight", "html-to-image", "Must be a positive integer.", "set_screenshot_height"), 470); end @fields['screenshot_height'] = height self end |
#setScreenshotWidth(width) ⇒ Object
Set the output image width in pixels.
-
width
- The accepted range is 96-65000. -
Returns - The converter object.
2771 2772 2773 2774 2775 2776 2777 2778 |
# File 'lib/pdfcrowd.rb', line 2771 def setScreenshotWidth(width) if (!(Integer(width) >= 96 && Integer(width) <= 65000)) raise Error.new(Pdfcrowd.(width, "setScreenshotWidth", "html-to-image", "The accepted range is 96-65000.", "set_screenshot_width"), 470); end @fields['screenshot_width'] = width self end |
#setSubprocessReferrer(referrer) ⇒ Object
3302 3303 3304 3305 |
# File 'lib/pdfcrowd.rb', line 3302 def setSubprocessReferrer(referrer) @fields['subprocess_referrer'] = referrer 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.
3235 3236 3237 3238 |
# File 'lib/pdfcrowd.rb', line 3235 def setTag(tag) @fields['tag'] = tag self end |
#setUseHttp(value) ⇒ Object
Specify whether to use HTTP or HTTPS when connecting to the 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.
3334 3335 3336 3337 |
# File 'lib/pdfcrowd.rb', line 3334 def setUseHttp(value) @helper.setUseHttp(value) self end |
#setUseMobileUserAgent(value) ⇒ Object
Use a mobile user agent.
-
value
- Set to true to use a mobile user agent. -
Returns - The converter object.
2868 2869 2870 2871 |
# File 'lib/pdfcrowd.rb', line 2868 def setUseMobileUserAgent(value) @fields['use_mobile_user_agent'] = value self end |
#setUsePrintMedia(value) ⇒ Object
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.
2823 2824 2825 2826 |
# File 'lib/pdfcrowd.rb', line 2823 def setUsePrintMedia(value) @fields['use_print_media'] = value self end |
#setUserAgent(agent) ⇒ Object
Set a custom user agent HTTP header. It can be useful if you are behind a proxy or a firewall.
-
agent
- The user agent string. -
Returns - The converter object.
3352 3353 3354 3355 |
# File 'lib/pdfcrowd.rb', line 3352 def setUserAgent(agent) @helper.setUserAgent(agent) self end |
#setVerifySslCertificates(value) ⇒ Object
Do not allow insecure HTTPS connections.
-
value
- Set to true to enable SSL certificate verification. -
Returns - The converter object.
2949 2950 2951 2952 |
# File 'lib/pdfcrowd.rb', line 2949 def setVerifySslCertificates(value) @fields['verify_ssl_certificates'] = value 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 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.
3076 3077 3078 3079 3080 3081 3082 3083 |
# File 'lib/pdfcrowd.rb', line 3076 def setWaitForElement(selectors) if (!(!selectors.nil? && !selectors.empty?)) raise Error.new(Pdfcrowd.(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) ⇒ Object
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.
2762 2763 2764 2765 |
# File 'lib/pdfcrowd.rb', line 2762 def setZipMainFilename(filename) @fields['zip_main_filename'] = filename self end |