class Pdfcrowd::HtmlToPdfClient
Conversion from HTML to PDF.
Public Class Methods
Constructor for the Pdfcrowd
API client.
-
user_name
- Your username atPdfcrowd
. -
api_key
- Your API key.
# File lib/pdfcrowd.rb, line 749 def initialize(user_name, api_key) @helper = ConnectionHelper.new(user_name, api_key) @fields = { 'input_format'=>'html', 'output_format'=>'pdf' } @file_id = 1 @files = {} @raw_data = {} end
Public Instance Methods
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 810 def convertFile(file) if (!(File.file?(file) && !File.zero?(file))) raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFile", "html-to-pdf", "The file must exist and not be empty.", "convert_file"), 470); end @files['file'] = file @helper.post(@fields, @files, @raw_data) end
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 836 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-pdf", "The string must not be empty.", "convert_file_to_file"), 470); end output_file = open(file_path, "wb") begin convertFileToStream(file, output_file) output_file.close() rescue Error => why output_file.close() FileUtils.rm(file_path) raise end end
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 823 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-pdf", "The file must exist and not be empty.", "convert_file_to_stream"), 470); end @files['file'] = file @helper.post(@fields, @files, @raw_data, out_stream) end
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 902 def convertStream(in_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data) end
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 920 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-pdf", "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
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 911 def convertStreamToStream(in_stream, out_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data, out_stream) end
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 856 def convertString(text) if (!(!text.nil? && !text.empty?)) raise Error.new(Pdfcrowd.create_invalid_value_message(text, "convertString", "html-to-pdf", "The string must not be empty.", "convert_string"), 470); end @fields['text'] = text @helper.post(@fields, @files, @raw_data) end
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 882 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-pdf", "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
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 869 def convertStringToStream(text, out_stream) if (!(!text.nil? && !text.empty?)) raise Error.new(Pdfcrowd.create_invalid_value_message(text, "convertStringToStream::text", "html-to-pdf", "The string must not be empty.", "convert_string_to_stream"), 470); end @fields['text'] = text @helper.post(@fields, @files, @raw_data, out_stream) end
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 764 def convertUrl(url) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrl", "html-to-pdf", "The supported protocols are http:// and https://.", "convert_url"), 470); end @fields['url'] = url @helper.post(@fields, @files, @raw_data) end
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 790 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-pdf", "The string must not be empty.", "convert_url_to_file"), 470); end output_file = open(file_path, "wb") begin convertUrlToStream(url, output_file) output_file.close() rescue Error => why output_file.close() FileUtils.rm(file_path) raise end end
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 777 def convertUrlToStream(url, out_stream) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrlToStream::url", "html-to-pdf", "The supported protocols are http:// and https://.", "convert_url_to_stream"), 470); end @fields['url'] = url @helper.post(@fields, @files, @raw_data, out_stream) end
Get the number of credits consumed by the last conversion.
-
Returns - The number of credits.
# File lib/pdfcrowd.rb, line 2150 def getConsumedCreditCount() return @helper.getConsumedCreditCount() end
Get the URL of the debug log for the last conversion.
-
Returns - The link to the debug log.
# File lib/pdfcrowd.rb, line 2135 def getDebugLogUrl() return @helper.getDebugLogUrl() end
Get the job id.
-
Returns - The unique job identifier.
# File lib/pdfcrowd.rb, line 2156 def getJobId() return @helper.getJobId() end
Get the size of the output in bytes.
-
Returns - The count of bytes.
# File lib/pdfcrowd.rb, line 2168 def getOutputSize() return @helper.getOutputSize() end
Get the total number of pages in the output document.
-
Returns - The page count.
# File lib/pdfcrowd.rb, line 2162 def getPageCount() return @helper.getPageCount() end
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 2144 def getRemainingCreditCount() return @helper.getRemainingCreditCount() end
Get the version details.
-
Returns - API version, converter version, and client version.
# File lib/pdfcrowd.rb, line 2174 def getVersion() return "client " + CLIENT_VERSION + ", API v2, converter " + @helper.getConverterVersion() end
Set the author of the PDF.
-
author
- The author. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1897 def setAuthor(author) @fields['author'] = author self end
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 1509 def setBlockAds(value) @fields['block_ads'] = value self end
Specify whether to position the document's window in the center of the screen.
-
value
- Set to true to center the window. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 2025 def setCenterWindow(value) @fields['center_window'] = value self end
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 2217 def setClientCertificate(certificate) if (!(File.file?(certificate) && !File.zero?(certificate))) raise Error.new(Pdfcrowd.create_invalid_value_message(certificate, "setClientCertificate", "html-to-pdf", "The file must exist and not be empty.", "set_client_certificate"), 470); end @files['client_certificate'] = certificate self end
A password for PKCS12 file with a client certificate if it is needed.
-
password
- -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 2230 def setClientCertificatePassword(password) @fields['client_certificate_password'] = password self end
Set the content area position and size. The content area enables to specify a web page area to be converted.
-
x
- Set the top left X coordinate of the content area. It is relative to the top left X coordinate of the print area. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value. -
y
- Set the top left Y coordinate of the content area. It is relative to the top left Y coordinate of the print area. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value. -
width
- Set the width of the content area. It should be at least 1 inch. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
height
- Set the height of the content area. It should be at least 1 inch. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1165 def setContentArea(x, y, width, height) setContentAreaX(x) setContentAreaY(y) setContentAreaWidth(width) setContentAreaHeight(height) self end
Set the height of the content area. It should be at least 1 inch.
-
height
- Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1149 def setContentAreaHeight(height) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(height) raise Error.new(Pdfcrowd.create_invalid_value_message(height, "setContentAreaHeight", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_content_area_height"), 470); end @fields['content_area_height'] = height self end
Set the width of the content area. It should be at least 1 inch.
-
width
- Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1136 def setContentAreaWidth(width) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(width) raise Error.new(Pdfcrowd.create_invalid_value_message(width, "setContentAreaWidth", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_content_area_width"), 470); end @fields['content_area_width'] = width self end
Set the top left X coordinate of the content area. It is relative to the top left X coordinate of the print area.
-
x
- Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1110 def setContentAreaX(x) unless /(?i)^0$|^\-?[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(x) raise Error.new(Pdfcrowd.create_invalid_value_message(x, "setContentAreaX", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value.", "set_content_area_x"), 470); end @fields['content_area_x'] = x self end
Set the top left Y coordinate of the content area. It is relative to the top left Y coordinate of the print area.
-
y
- Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1123 def setContentAreaY(y) unless /(?i)^0$|^\-?[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(y) raise Error.new(Pdfcrowd.create_invalid_value_message(y, "setContentAreaY", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value.", "set_content_area_y"), 470); end @fields['content_area_y'] = y self end
A 2D transformation matrix applied to the main contents on each page. The origin [0,0] is located at the top-left corner of the contents. The resolution is 72 dpi.
-
matrix
- A comma separated string of matrix elements: “scaleX,skewX,transX,skewY,scaleY,transY” -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 2252 def setContentsMatrix(matrix) @fields['contents_matrix'] = matrix self end
Specify which image types will be converted to JPEG. Converting lossless compression image formats (PNG, GIF, …) to JPEG may result in a smaller PDF file.
-
images
- The image category. Allowed values are none, opaque, all. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1790 def setConvertImagesToJpeg(images) unless /(?i)^(none|opaque|all)$/.match(images) raise Error.new(Pdfcrowd.create_invalid_value_message(images, "setConvertImagesToJpeg", "html-to-pdf", "Allowed values are none, opaque, all.", "set_convert_images_to_jpeg"), 470); end @fields['convert_images_to_jpeg'] = images self end
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 2307 def setConverterVersion(version) unless /(?i)^(latest|20.10|18.10)$/.match(version) raise Error.new(Pdfcrowd.create_invalid_value_message(version, "setConverterVersion", "html-to-pdf", "Allowed values are latest, 20.10, 18.10.", "set_converter_version"), 470); end @helper.setConverterVersion(version) self end
Set cookies that are sent in Pdfcrowd
HTTP requests.
-
cookies
- The cookie string. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1565 def setCookies(cookies) @fields['cookies'] = cookies self end
Specifies behavior in presence of CSS @page rules. It may affect the page size, margins and orientation.
-
mode
- The page rule mode. Allowed values are default, mode1, mode2. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1177 def setCssPageRuleMode(mode) unless /(?i)^(default|mode1|mode2)$/.match(mode) raise Error.new(Pdfcrowd.create_invalid_value_message(mode, "setCssPageRuleMode", "html-to-pdf", "Allowed values are default, mode1, mode2.", "set_css_page_rule_mode"), 470); end @fields['css_page_rule_mode'] = mode self end
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 1636 def setCustomHttpHeader(header) unless /^.+:.+$/.match(header) raise Error.new(Pdfcrowd.create_invalid_value_message(header, "setCustomHttpHeader", "html-to-pdf", "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
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 1610 def setCustomJavascript(javascript) if (!(!javascript.nil? && !javascript.empty?)) raise Error.new(Pdfcrowd.create_invalid_value_message(javascript, "setCustomJavascript", "html-to-pdf", "The string must not be empty.", "set_custom_javascript"), 470); end @fields['custom_javascript'] = javascript self end
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 2101 def setDataAutoEscape(value) @fields['data_auto_escape'] = value self end
Set the encoding of the data file set by setDataFile.
-
encoding
- The data file encoding. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 2083 def setDataEncoding(encoding) @fields['data_encoding'] = encoding self end
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 2061 def setDataFile(data_file) @files['data_file'] = data_file self end
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 2070 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-pdf", "Allowed values are auto, json, xml, yaml, csv.", "set_data_format"), 470); end @fields['data_format'] = data_format self end
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 2092 def setDataIgnoreUndefined(value) @fields['data_ignore_undefined'] = value self end
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 2119 def setDataOptions(options) @fields['data_options'] = options self end
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 2052 def setDataString(data_string) @fields['data_string'] = data_string self end
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 2110 def setDataTrimBlocks(value) @fields['data_trim_blocks'] = value self end
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 2128 def setDebugLog(value) @fields['debug_log'] = value self end
Set the default HTML content text encoding.
-
encoding
- The text encoding of the HTML content. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1518 def setDefaultEncoding(encoding) @fields['default_encoding'] = encoding self end
Do not load images.
-
value
- Set to true to disable loading of images. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1478 def setDisableImageLoading(value) @fields['disable_image_loading'] = value self end
Do not execute JavaScript.
-
value
- Set to true to disable JavaScript in web pages. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1469 def setDisableJavascript(value) @fields['disable_javascript'] = value self end
Disable automatic height adjustment that compensates for pixel to point rounding errors.
-
value
- Set to true to disable automatic height scale. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 2279 def setDisablePageHeightOptimization(value) @fields['disable_page_height_optimization'] = value self end
Disable loading fonts from remote sources.
-
value
- Set to true disable loading remote fonts. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1487 def setDisableRemoteFonts(value) @fields['disable_remote_fonts'] = value self end
Specify whether the window's title bar should display the document title. If false , the title bar should instead display the name of the PDF file containing the document.
-
value
- Set to true to display the title. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 2034 def setDisplayTitle(value) @fields['display_title'] = value self end
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 1662 def setElementToConvert(selectors) if (!(!selectors.nil? && !selectors.empty?)) raise Error.new(Pdfcrowd.create_invalid_value_message(selectors, "setElementToConvert", "html-to-pdf", "The string must not be empty.", "set_element_to_convert"), 470); end @fields['element_to_convert'] = selectors self end
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 1675 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-pdf", "Allowed values are cut-out, remove-siblings, hide-siblings.", "set_element_to_convert_mode"), 470); end @fields['element_to_convert_mode'] = mode self end
Encrypt the PDF. This prevents search engines from indexing the contents.
-
value
- Set to true to enable PDF encryption. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1825 def setEncrypt(value) @fields['encrypt'] = value self end
The page header is not printed on the specified pages.
-
pages
- List of physical page numbers. Negative numbers count backwards from the last page: -1 is the last page, -2 is the last but one page, and so on. A comma separated list of page numbers. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1295 def setExcludeHeaderOnPages(pages) unless /^(?:\s*\-?\d+\s*,)*\s*\-?\d+\s*$/.match(pages) raise Error.new(Pdfcrowd.create_invalid_value_message(pages, "setExcludeHeaderOnPages", "html-to-pdf", "A comma separated list of page numbers.", "set_exclude_header_on_pages"), 470); end @fields['exclude_header_on_pages'] = pages self end
Extract meta tags (author, keywords and description) from the input HTML and use them in the output PDF.
-
value
- Set to true to extract meta tags. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1915 def setExtractMetaTags(value) @fields['extract_meta_tags'] = value self end
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 1592 def setFailOnAnyUrlError(fail_on_error) @fields['fail_on_any_url_error'] = fail_on_error self end
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 1583 def setFailOnMainUrlError(fail_on_error) @fields['fail_on_main_url_error'] = fail_on_error self end
Specify whether to resize the document's window to fit the size of the first displayed page.
-
value
- Set to true to resize the window. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 2016 def setFitWindow(value) @fields['fit_window'] = value self end
Set the header height.
-
height
- Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1216 def setHeaderHeight(height) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(height) raise Error.new(Pdfcrowd.create_invalid_value_message(height, "setHeaderHeight", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_header_height"), 470); end @fields['header_height'] = height self end
Use the specified HTML code as the page header. The following classes can be used in the HTML. The content of the respective elements will be expanded as follows: pdfcrowd-page-count - the total page count of printed pages pdfcrowd-page-number - the current page number pdfcrowd-source-url - the source URL of a converted document The following attributes can be used: data-pdfcrowd-number-format - specifies the type of the used numerals. Allowed values: arabic - Arabic numerals, they are used by default roman - Roman numerals eastern-arabic - Eastern Arabic numerals bengali - Bengali numerals devanagari - Devanagari numerals thai - Thai numerals east-asia - Chinese, Vietnamese, Japanese and Korean numerals chinese-formal - Chinese formal numerals Please contact us if you need another type of numerals. Example: <span class='pdfcrowd-page-number' data-pdfcrowd-number-format='roman'></span> data-pdfcrowd-placement - specifies where to place the source URL. Allowed values: The URL is inserted to the content Example: <span class='pdfcrowd-source-url'></span> will produce <span>example.com> href - the URL is set to the href attribute Example: <a class='pdfcrowd-source-url' data-pdfcrowd-placement='href'>Link to source</a> will produce <a href='http://example.comexample.com’>http://example.com>
-
html
- The string must not be empty. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1203 def setHeaderHtml(html) if (!(!html.nil? && !html.empty?)) raise Error.new(Pdfcrowd.create_invalid_value_message(html, "setHeaderHtml", "html-to-pdf", "The string must not be empty.", "set_header_html"), 470); end @fields['header_html'] = html self end
A 2D transformation matrix applied to the page header contents. The origin [0,0] is located at the top-left corner of the header. The resolution is 72 dpi.
-
matrix
- A comma separated string of matrix elements: “scaleX,skewX,transX,skewY,scaleY,transY” -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 2261 def setHeaderMatrix(matrix) @fields['header_matrix'] = matrix self end
Load an HTML code from the specified URL and use it as the page header. The following classes can be used in the HTML. The content of the respective elements will be expanded as follows: pdfcrowd-page-count - the total page count of printed pages pdfcrowd-page-number - the current page number pdfcrowd-source-url - the source URL of a converted document The following attributes can be used: data-pdfcrowd-number-format - specifies the type of the used numerals. Allowed values: arabic - Arabic numerals, they are used by default roman - Roman numerals eastern-arabic - Eastern Arabic numerals bengali - Bengali numerals devanagari - Devanagari numerals thai - Thai numerals east-asia - Chinese, Vietnamese, Japanese and Korean numerals chinese-formal - Chinese formal numerals Please contact us if you need another type of numerals. Example: <span class='pdfcrowd-page-number' data-pdfcrowd-number-format='roman'></span> data-pdfcrowd-placement - specifies where to place the source URL. Allowed values: The URL is inserted to the content Example: <span class='pdfcrowd-source-url'></span> will produce <span>example.com> href - the URL is set to the href attribute Example: <a class='pdfcrowd-source-url' data-pdfcrowd-placement='href'>Link to source</a> will produce <a href='http://example.comexample.com’>http://example.com>
-
url
- The supported protocols are http:// and https://. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1190 def setHeaderUrl(url) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.create_invalid_value_message(url, "setHeaderUrl", "html-to-pdf", "The supported protocols are http:// and https://.", "set_header_url"), 470); end @fields['header_url'] = url self end
Specify whether to hide the viewer application's menu bar when the document is active.
-
value
- Set to true to hide the menu bar. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1998 def setHideMenubar(value) @fields['hide_menubar'] = value self end
Specify whether to hide the viewer application's tool bars when the document is active.
-
value
- Set to true to hide tool bars. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1989 def setHideToolbar(value) @fields['hide_toolbar'] = value self end
Specify whether to hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed.
-
value
- Set to true to hide ui elements. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 2007 def setHideWindowUi(value) @fields['hide_window_ui'] = value self end
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 1555 def setHttpAuth(user_name, password) setHttpAuthUserName(user_name) setHttpAuthPassword(password) self end
Set the HTTP authentication password.
-
password
- The password. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1545 def setHttpAuthPassword(password) @fields['http_auth_password'] = password self end
Set the HTTP authentication user name.
-
user_name
- The user name. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1536 def setHttpAuthUserName(user_name) @fields['http_auth_user_name'] = user_name self end
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 2191 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-pdf", "The value must have format DOMAIN_OR_IP_ADDRESS:PORT.", "set_http_proxy"), 470); end @fields['http_proxy'] = proxy self end
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 2204 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-pdf", "The value must have format DOMAIN_OR_IP_ADDRESS:PORT.", "set_https_proxy"), 470); end @fields['https_proxy'] = proxy self end
Set the DPI of images in PDF. A lower DPI may result in a smaller PDF file. If the specified DPI is higher than the actual image DPI, the original image DPI is retained (no upscaling is performed). Use 0 to leave the images unaltered.
-
dpi
- The DPI value. Must be a positive integer number or 0. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1803 def setImageDpi(dpi) if (!(Integer(dpi) >= 0)) raise Error.new(Pdfcrowd.create_invalid_value_message(dpi, "setImageDpi", "html-to-pdf", "Must be a positive integer number or 0.", "set_image_dpi"), 470); end @fields['image_dpi'] = dpi self end
Display the specified page when the document is opened.
-
page
- Must be a positive integer number. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1963 def setInitialPage(page) if (!(Integer(page) > 0)) raise Error.new(Pdfcrowd.create_invalid_value_message(page, "setInitialPage", "html-to-pdf", "Must be a positive integer number.", "set_initial_page"), 470); end @fields['initial_page'] = page self end
Specify the initial page zoom in percents when the document is opened.
-
zoom
- Must be a positive integer number. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1976 def setInitialZoom(zoom) if (!(Integer(zoom) > 0)) raise Error.new(Pdfcrowd.create_invalid_value_message(zoom, "setInitialZoom", "html-to-pdf", "Must be a positive integer number.", "set_initial_zoom"), 470); end @fields['initial_zoom'] = zoom self end
Specify how the page should be displayed when opened.
-
zoom_type
- Allowed values are fit-width, fit-height, fit-page. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1950 def setInitialZoomType(zoom_type) unless /(?i)^(fit-width|fit-height|fit-page)$/.match(zoom_type) raise Error.new(Pdfcrowd.create_invalid_value_message(zoom_type, "setInitialZoomType", "html-to-pdf", "Allowed values are fit-width, fit-height, fit-page.", "set_initial_zoom_type"), 470); end @fields['initial_zoom_type'] = zoom_type self end
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 1649 def setJavascriptDelay(delay) if (!(Integer(delay) >= 0)) raise Error.new(Pdfcrowd.create_invalid_value_message(delay, "setJavascriptDelay", "html-to-pdf", "Must be a positive integer number or 0.", "set_javascript_delay"), 470); end @fields['javascript_delay'] = delay self end
Set the quality of embedded JPEG images. A lower quality results in a smaller PDF file but can lead to compression artifacts.
-
quality
- The percentage value. The value must be in the range 1-100. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1777 def setJpegQuality(quality) if (!(Integer(quality) >= 1 && Integer(quality) <= 100)) raise Error.new(Pdfcrowd.create_invalid_value_message(quality, "setJpegQuality", "html-to-pdf", "The value must be in the range 1-100.", "set_jpeg_quality"), 470); end @fields['jpeg_quality'] = quality self end
Associate keywords with the document.
-
keywords
- The string with the keywords. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1906 def setKeywords(keywords) @fields['keywords'] = keywords self end
Set the internal DPI resolution used for positioning of PDF contents. It can help in situations when there are small inaccuracies in the PDF. It is recommended to use values that are a multiple of 72, such as 288 or 360.
-
dpi
- The DPI value. The value must be in the range of 72-600. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 2239 def setLayoutDpi(dpi) if (!(Integer(dpi) >= 72 && Integer(dpi) <= 600)) raise Error.new(Pdfcrowd.create_invalid_value_message(dpi, "setLayoutDpi", "html-to-pdf", "The value must be in the range of 72-600.", "set_layout_dpi"), 470); end @fields['layout_dpi'] = dpi self end
Create linearized PDF. This is also known as Fast Web View.
-
value
- Set to true to create linearized PDF. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1816 def setLinearize(value) @fields['linearize'] = value self end
Specifies how iframes are handled.
-
iframes
- Allowed values are all, same-origin, none. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1496 def setLoadIframes(iframes) unless /(?i)^(all|same-origin|none)$/.match(iframes) raise Error.new(Pdfcrowd.create_invalid_value_message(iframes, "setLoadIframes", "html-to-pdf", "Allowed values are all, same-origin, none.", "set_load_iframes"), 470); end @fields['load_iframes'] = iframes self end
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 1527 def setLocale(locale) @fields['locale'] = locale self end
Add special CSS classes to the main document's body element. This allows applying custom styling based on these classes: pdfcrowd-page-X - where X is the current page number pdfcrowd-page-odd - odd page pdfcrowd-page-even - even page Warning: If your custom styling affects the contents area size (e.g. by using different margins, padding, border width), the resulting PDF may contain duplicit contents or some contents may be missing.
-
value
- Set to true to add the special CSS classes. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 2289 def setMainDocumentCssAnnotation(value) @fields['main_document_css_annotation'] = value self end
Set the output page bottom margin.
-
bottom
- Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1038 def setMarginBottom(bottom) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(bottom) raise Error.new(Pdfcrowd.create_invalid_value_message(bottom, "setMarginBottom", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_margin_bottom"), 470); end @fields['margin_bottom'] = bottom self end
Set the output page left margin.
-
left
- Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1051 def setMarginLeft(left) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(left) raise Error.new(Pdfcrowd.create_invalid_value_message(left, "setMarginLeft", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_margin_left"), 470); end @fields['margin_left'] = left self end
Set the output page right margin.
-
right
- Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1025 def setMarginRight(right) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(right) raise Error.new(Pdfcrowd.create_invalid_value_message(right, "setMarginRight", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_margin_right"), 470); end @fields['margin_right'] = right self end
Set the output page top margin.
-
top
- Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1012 def setMarginTop(top) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(top) raise Error.new(Pdfcrowd.create_invalid_value_message(top, "setMarginTop", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_margin_top"), 470); end @fields['margin_top'] = top self end
Apply each page of the specified PDF to the background of the corresponding page of the output PDF.
-
background
- The file path to a local background PDF file. The file must exist and not be empty. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1412 def setMultipageBackground(background) if (!(File.file?(background) && !File.zero?(background))) raise Error.new(Pdfcrowd.create_invalid_value_message(background, "setMultipageBackground", "html-to-pdf", "The file must exist and not be empty.", "set_multipage_background"), 470); end @files['multipage_background'] = background self end
Load a background PDF from the specified URL and apply each page of the specified background PDF to the corresponding page of the output PDF.
-
url
- The supported protocols are http:// and https://. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1425 def setMultipageBackgroundUrl(url) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.create_invalid_value_message(url, "setMultipageBackgroundUrl", "html-to-pdf", "The supported protocols are http:// and https://.", "set_multipage_background_url"), 470); end @fields['multipage_background_url'] = url self end
Apply each page of the specified watermark PDF to the corresponding page of the output PDF.
-
watermark
- The file path to a local watermark PDF file. The file must exist and not be empty. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1360 def setMultipageWatermark(watermark) if (!(File.file?(watermark) && !File.zero?(watermark))) raise Error.new(Pdfcrowd.create_invalid_value_message(watermark, "setMultipageWatermark", "html-to-pdf", "The file must exist and not be empty.", "set_multipage_watermark"), 470); end @files['multipage_watermark'] = watermark self end
Load a watermark PDF from the specified URL and apply each page of the specified watermark PDF to the corresponding page of the output PDF.
-
url
- The supported protocols are http:// and https://. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1373 def setMultipageWatermarkUrl(url) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.create_invalid_value_message(url, "setMultipageWatermarkUrl", "html-to-pdf", "The supported protocols are http:// and https://.", "set_multipage_watermark_url"), 470); end @fields['multipage_watermark_url'] = url self end
Do not print the background graphics.
-
value
- Set to true to disable the background graphics. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1460 def setNoBackground(value) @fields['no_background'] = value self end
Disallow text and graphics extraction from the output PDF.
-
value
- Set to true to set the no-copy flag in the output PDF. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1870 def setNoCopy(value) @fields['no_copy'] = value self end
Disable page margins.
-
value
- Set to true to disable margins. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1064 def setNoMargins(value) @fields['no_margins'] = value self end
Disallow modification of the output PDF.
-
value
- Set to true to set the read-only only flag in the output PDF. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1861 def setNoModify(value) @fields['no_modify'] = value self end
Disallow printing of the output PDF.
-
value
- Set to true to set the no-print flag in the output PDF. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1852 def setNoPrint(value) @fields['no_print'] = value self end
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 1601 def setNoXpdfcrowdHeader(value) @fields['no_xpdfcrowd_header'] = value self end
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 1623 def setOnLoadJavascript(javascript) if (!(!javascript.nil? && !javascript.empty?)) raise Error.new(Pdfcrowd.create_invalid_value_message(javascript, "setOnLoadJavascript", "html-to-pdf", "The string must not be empty.", "set_on_load_javascript"), 470); end @fields['on_load_javascript'] = javascript self end
Set the output page orientation.
-
orientation
- Allowed values are landscape, portrait. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 999 def setOrientation(orientation) unless /(?i)^(landscape|portrait)$/.match(orientation) raise Error.new(Pdfcrowd.create_invalid_value_message(orientation, "setOrientation", "html-to-pdf", "Allowed values are landscape, portrait.", "set_orientation"), 470); end @fields['orientation'] = orientation self end
Protect the PDF with an owner password. Supplying an owner password grants unlimited access to the PDF including changing the passwords and access permissions.
-
password
- The owner password. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1843 def setOwnerPassword(password) @fields['owner_password'] = password self end
Apply the first page of the specified PDF to the background of every page of the output PDF.
-
background
- The file path to a local background PDF file. The file must exist and not be empty. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1386 def setPageBackground(background) if (!(File.file?(background) && !File.zero?(background))) raise Error.new(Pdfcrowd.create_invalid_value_message(background, "setPageBackground", "html-to-pdf", "The file must exist and not be empty.", "set_page_background"), 470); end @files['page_background'] = background self end
The page background color in RGB or RGBA hexadecimal format. The color fills the entire page regardless of the margins.
-
color
- The value must be in RRGGBB or RRGGBBAA hexadecimal format. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1438 def setPageBackgroundColor(color) unless /^[0-9a-fA-F]{6,8}$/.match(color) raise Error.new(Pdfcrowd.create_invalid_value_message(color, "setPageBackgroundColor", "html-to-pdf", "The value must be in RRGGBB or RRGGBBAA hexadecimal format.", "set_page_background_color"), 470); end @fields['page_background_color'] = color self end
Load a background PDF from the specified URL and apply the first page of the background PDF to every page of the output PDF.
-
url
- The supported protocols are http:// and https://. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1399 def setPageBackgroundUrl(url) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.create_invalid_value_message(url, "setPageBackgroundUrl", "html-to-pdf", "The supported protocols are http:// and https://.", "set_page_background_url"), 470); end @fields['page_background_url'] = url self end
Set the output page dimensions.
-
width
- Set the output page width. The safe maximum is 200in otherwise some PDF viewers may be unable to open the PDF. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
height
- Set the output page height. Use -1 for a single page PDF. The safe maximum is 200in otherwise some PDF viewers may be unable to open the PDF. Can be -1 or specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 989 def setPageDimensions(width, height) setPageWidth(width) setPageHeight(height) self end
Set the output page height. Use -1 for a single page PDF. The safe maximum is 200in otherwise some PDF viewers may be unable to open the PDF.
-
height
- Can be -1 or specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 975 def setPageHeight(height) unless /(?i)^0$|^\-1$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(height) raise Error.new(Pdfcrowd.create_invalid_value_message(height, "setPageHeight", "html-to-pdf", "Can be -1 or specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_page_height"), 470); end @fields['page_height'] = height self end
Specify the page layout to be used when the document is opened.
-
layout
- Allowed values are single-page, one-column, two-column-left, two-column-right. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1924 def setPageLayout(layout) unless /(?i)^(single-page|one-column|two-column-left|two-column-right)$/.match(layout) raise Error.new(Pdfcrowd.create_invalid_value_message(layout, "setPageLayout", "html-to-pdf", "Allowed values are single-page, one-column, two-column-left, two-column-right.", "set_page_layout"), 470); end @fields['page_layout'] = layout self end
Set the output page margins.
-
top
- Set the output page top margin. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
right
- Set the output page right margin. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
bottom
- Set the output page bottom margin. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
left
- Set the output page left margin. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1076 def setPageMargins(top, right, bottom, left) setMarginTop(top) setMarginRight(right) setMarginBottom(bottom) setMarginLeft(left) self end
Specify how the document should be displayed when opened.
-
mode
- Allowed values are full-screen, thumbnails, outlines. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1937 def setPageMode(mode) unless /(?i)^(full-screen|thumbnails|outlines)$/.match(mode) raise Error.new(Pdfcrowd.create_invalid_value_message(mode, "setPageMode", "html-to-pdf", "Allowed values are full-screen, thumbnails, outlines.", "set_page_mode"), 470); end @fields['page_mode'] = mode self end
Set an offset between physical and logical page numbers.
-
offset
- Integer specifying page offset. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1101 def setPageNumberingOffset(offset) @fields['page_numbering_offset'] = offset self end
Set the output page size.
-
size
- Allowed values are A0, A1, A2, A3, A4, A5, A6, Letter. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 949 def setPageSize(size) unless /(?i)^(A0|A1|A2|A3|A4|A5|A6|Letter)$/.match(size) raise Error.new(Pdfcrowd.create_invalid_value_message(size, "setPageSize", "html-to-pdf", "Allowed values are A0, A1, A2, A3, A4, A5, A6, Letter.", "set_page_size"), 470); end @fields['page_size'] = size self end
Apply the first page of the watermark PDF to every page of the output PDF.
-
watermark
- The file path to a local watermark PDF file. The file must exist and not be empty. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1334 def setPageWatermark(watermark) if (!(File.file?(watermark) && !File.zero?(watermark))) raise Error.new(Pdfcrowd.create_invalid_value_message(watermark, "setPageWatermark", "html-to-pdf", "The file must exist and not be empty.", "set_page_watermark"), 470); end @files['page_watermark'] = watermark self end
Load a watermark PDF from the specified URL and apply the first page of the watermark PDF to every page of the output PDF.
-
url
- The supported protocols are http:// and https://. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1347 def setPageWatermarkUrl(url) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.create_invalid_value_message(url, "setPageWatermarkUrl", "html-to-pdf", "The supported protocols are http:// and https://.", "set_page_watermark_url"), 470); end @fields['page_watermark_url'] = url self end
Set the output page width. The safe maximum is 200in otherwise some PDF viewers may be unable to open the PDF.
-
width
- Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 962 def setPageWidth(width) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(width) raise Error.new(Pdfcrowd.create_invalid_value_message(width, "setPageWidth", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_page_width"), 470); end @fields['page_width'] = width self end
Set the page range to print.
-
pages
- A comma separated list of page numbers or ranges. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1088 def setPrintPageRange(pages) unless /^(?:\s*(?:\d+|(?:\d*\s*\-\s*\d+)|(?:\d+\s*\-\s*\d*))\s*,\s*)*\s*(?:\d+|(?:\d*\s*\-\s*\d+)|(?:\d+\s*\-\s*\d*))\s*$/.match(pages) raise Error.new(Pdfcrowd.create_invalid_value_message(pages, "setPrintPageRange", "html-to-pdf", "A comma separated list of page numbers or ranges.", "set_print_page_range"), 470); end @fields['print_page_range'] = pages self end
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 2342 def setProxy(host, port, user_name, password) @helper.setProxy(host, port, user_name, password) self end
Set the rendering mode.
-
mode
- The rendering mode. Allowed values are default, viewport. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1738 def setRenderingMode(mode) unless /(?i)^(default|viewport)$/.match(mode) raise Error.new(Pdfcrowd.create_invalid_value_message(mode, "setRenderingMode", "html-to-pdf", "Allowed values are default, viewport.", "set_rendering_mode"), 470); end @fields['rendering_mode'] = mode self end
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 2351 def setRetryCount(count) @helper.setRetryCount(count) self end
Set the predominant reading order for text to right-to-left. This option has no direct effect on the document's contents or page numbering but can be used to determine the relative positioning of pages when displayed side by side or printed n-up
-
value
- Set to true to set right-to-left reading order. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 2043 def setRightToLeft(value) @fields['right_to_left'] = value self end
Set the scaling factor (zoom) for the main page area.
-
factor
- The percentage value. The value must be in the range 10-500. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1764 def setScaleFactor(factor) if (!(Integer(factor) >= 10 && Integer(factor) <= 500)) raise Error.new(Pdfcrowd.create_invalid_value_message(factor, "setScaleFactor", "html-to-pdf", "The value must be in the range 10-500.", "set_scale_factor"), 470); end @fields['scale_factor'] = factor self end
Specifies the scaling mode used for fitting the HTML contents to the print area.
-
mode
- The smart scaling mode. Allowed values are default, disabled, viewport-fit, content-fit, single-page-fit, mode1. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1751 def setSmartScalingMode(mode) unless /(?i)^(default|disabled|viewport-fit|content-fit|single-page-fit|mode1)$/.match(mode) raise Error.new(Pdfcrowd.create_invalid_value_message(mode, "setSmartScalingMode", "html-to-pdf", "Allowed values are default, disabled, viewport-fit, content-fit, single-page-fit, mode1.", "set_smart_scaling_mode"), 470); end @fields['smart_scaling_mode'] = mode self end
Set the subject of the PDF.
-
subject
- The subject. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1888 def setSubject(subject) @fields['subject'] = subject self end
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 2182 def setTag(tag) @fields['tag'] = tag self end
Set the title of the PDF.
-
title
- The title. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1879 def setTitle(title) @fields['title'] = title self end
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 2321 def setUseHttp(value) @helper.setUseHttp(value) self end
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 1451 def setUsePrintMedia(value) @fields['use_print_media'] = value self end
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 2330 def setUserAgent(agent) @helper.setUserAgent(agent) self end
Protect the PDF with a user password. When a PDF has a user password, it must be supplied in order to view the document and to perform operations allowed by the access permissions.
-
password
- The user password. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1834 def setUserPassword(password) @fields['user_password'] = password self end
Do not allow insecure HTTPS connections.
-
value
- Set to true to enable SSL certificate verification. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1574 def setVerifySslCertificates(value) @fields['verify_ssl_certificates'] = value self end
Set the viewport size. The viewport is the user's visible area of the page.
-
width
- Set the viewport width in pixels. The viewport is the user's visible area of the page. The value must be in the range 96-65000. -
height
- Set the viewport height in pixels. The viewport is the user's visible area of the page. Must be a positive integer number. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1728 def setViewport(width, height) setViewportWidth(width) setViewportHeight(height) self end
Set the viewport height in pixels. The viewport is the user's visible area of the page.
-
height
- Must be a positive integer number. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1714 def setViewportHeight(height) if (!(Integer(height) > 0)) raise Error.new(Pdfcrowd.create_invalid_value_message(height, "setViewportHeight", "html-to-pdf", "Must be a positive integer number.", "set_viewport_height"), 470); end @fields['viewport_height'] = height self end
Set the viewport width in pixels. The viewport is the user's visible area of the page.
-
width
- The value must be in the range 96-65000. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1701 def setViewportWidth(width) if (!(Integer(width) >= 96 && Integer(width) <= 65000)) raise Error.new(Pdfcrowd.create_invalid_value_message(width, "setViewportWidth", "html-to-pdf", "The value must be in the range 96-65000.", "set_viewport_width"), 470); end @fields['viewport_width'] = width self end
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 1688 def setWaitForElement(selectors) if (!(!selectors.nil? && !selectors.empty?)) raise Error.new(Pdfcrowd.create_invalid_value_message(selectors, "setWaitForElement", "html-to-pdf", "The string must not be empty.", "set_wait_for_element"), 470); end @fields['wait_for_element'] = selectors self end
Set the file name of the header HTML document stored in the input archive. Use this method if the input archive contains multiple HTML documents.
-
filename
- The file name. -
Returns - The converter object.
# File lib/pdfcrowd.rb, line 1229 def setZipHeaderFilename(filename) @fields['zip_header_filename'] = filename self end
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 940 def setZipMainFilename(filename) @fields['zip_main_filename'] = filename self end