HTML to Image / Command Line Reference

Conversion from HTML to image.

usage: html2image [options] source
source
Source to be converted. It can be URL, path to a local file or '-' to use stdin as an input text.

Options

Conversion Format

-output-format
The format of the output file.
Allowed values:
  • png
  • jpg
  • gif
  • tiff
  • bmp
  • ico
  • ppm
  • pgm
  • pbm
  • pnm
  • psb
  • pct
  • ras
  • tga
  • sgi
  • sun
  • webp
Default: png

Image Output

-screenshot-width
Set the output image width in pixels.
Constraint:
  • The value must be in the range 96-65000.
Default: 1024
Example:
  • Full HD width.
    1920
-screenshot-height
Set the output image height in pixels. If it is not specified, actual document height is used.
Constraint:
  • Must be a positive integer number.
Example:
  • Full HD height.
    1080
-scale-factor
Set the scaling factor (zoom) for the output image.
Constraint:
  • Must be a positive integer number.
Default: 100
Example:
  • 50
-background-color
The output image background color.
Availability: API client >= 5.0.0, converter >= 20.10. See versioning.
Constraint:
  • The value must be in RRGGBB or RRGGBBAA hexadecimal format.
Examples:
  • red color
    "FF0000"
  • fully transparent background
    "00000000"
  • green color with 50% opacity
    "00ff0080"
  • green color
    "00ff00"

General Options

-use-print-media
Use the print version of the page if available (@media print).
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-no-background
Do not print the background graphics.
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-disable-javascript
Do not execute JavaScript.
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-disable-image-loading
Do not load images.
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-disable-remote-fonts
Disable loading fonts from remote sources.
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-use-mobile-user-agent
Use a mobile user agent.
Availability: API client >= 5.3.0, converter >= 20.10. See versioning.
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-load-iframes
Specifies how iframes are handled.
Availability: API client >= 5.0.0, converter >= 20.10. See versioning.
Allowed values:
  • all
    All iframes are loaded.
  • same-origin
    Only iframes with the same origin as the main page are loaded.
  • none
    Iframe loading is disabled.
Default: all
-block-ads
Try to block ads. Enabling this option can produce smaller output and speed up the conversion.
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-default-encoding
Set the default HTML content text encoding.
Default: auto detect
Examples:
  • Set to use Latin-2 encoding.
    "iso8859-2"
  • Set to use UTF-8 encoding.
    "utf-8"
-locale
Set the locale for the conversion. This may affect the output format of dates, times and numbers.
Availability: API client >= 5.0.0, converter >= 20.10. See versioning.
Default: en-US
Example:
  • Set to use Japanese locale.
    "ja-JP"
-http-auth-user-name
Set the HTTP authentication user name.
Example:
  • "John"
-http-auth-password
Set the HTTP authentication password.
Example:
  • "123456"
-cookies
Set cookies that are sent in Pdfcrowd HTTP requests.
Example:
  • "session=6d7184b3bf35;token=2710"
-verify-ssl-certificates
Do not allow insecure HTTPS connections.
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-fail-on-main-url-error
Abort the conversion if the main URL HTTP status code is greater than or equal to 400.
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-fail-on-any-url-error
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.
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-no-xpdfcrowd-header
Do not send the X-Pdfcrowd HTTP header in Pdfcrowd HTTP requests.
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-custom-css
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.
Availability: API client >= 5.14.0, converter >= 20.10. See versioning.
Examples:
  • Set the page background color to gray.
    "body { background-color: gray; }"
  • Do not show nav HTML elements and the element with ad-block ID in the output PDF.
    "nav, #ad-block { display: none !important; }"
-custom-javascript
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.
Example:
  • Set the page background color to gray.
    "document.body.style.setProperty('background-color', 'gray', 'important')"
-on-load-javascript
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.
Example:
  • Set the page background color to gray.
    "document.body.style.setProperty('background-color', 'gray', 'important')"
-custom-http-header
Set a custom HTTP header that is sent in Pdfcrowd HTTP requests.
Constraint:
  • A string containing the header name and value separated by a colon.
Example:
  • "X-My-Client-ID:k2017-12345"
-javascript-delay
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.
Constraint:
  • Must be a positive integer number or 0.
Default: 200
Example:
  • Wait for 2 seconds.
    2000
-element-to-convert
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.
Examples:
  • The first element with the id main-content is converted.
    "#main-content"
  • The first element with the class name main-content is converted.
    ".main-content"
  • The first element with the tag name table is converted.
    "table"
  • The first element with the tag name table or with the id main-content is converted.
    "table, #main-content"
  • The first element <p class="article"> within <div class="user-panel main"> is converted.
    "div.user-panel.main p.article"
-element-to-convert-mode
Specify the DOM handling when only a part of the document is converted. This can affect the CSS rules used.
Allowed values:
  • cut-out
    The element and its children are cut out of the document.
  • remove-siblings
    All element's siblings are removed.
  • hide-siblings
    All element's siblings are hidden.
Default: cut-out
-wait-for-element
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.
Examples:
  • Wait until an element with the id main-content is found.
    "#main-content"
  • Wait until an element with the class name main-content is found.
    ".main-content"
  • Wait until an element with the tag name table is found.
    "table"
  • Wait until an element with the tag name table or with the id main-content is found.
    "table, #main-content"
  • Wait until <p class="article"> is found within <div class="user-panel main">.
    "div.user-panel.main p.article"
-auto-detect-element-to-convert
The main HTML element for conversion is detected automatically.
Availability: API client >= 5.5.0, converter >= 20.10. See versioning.
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-readability-enhancements
The input HTML is automatically enhanced to improve the readability.
Availability: API client >= 5.5.0, converter >= 20.10. See versioning.
Allowed values:
  • none
    No enhancements are used.
  • readability-v1
    Version 1 of the enhancements is used.
  • readability-v2
    Version 2 of the enhancements is used.
  • readability-v3
    Version 3 of the enhancements is used.
  • readability-v4
    Version 4 of the enhancements is used.
Default: none

Data

Methods related to HTML template rendering.

-data-string
Set the input data for template rendering. The data format can be JSON, XML, YAML or CSV.
Example:
  • JSON data.
    "{"recipient": "Anna May", "sender": "John Doe"}"
-data-file
Load the input data for template rendering from the specified file. The data format can be JSON, XML, YAML or CSV.
Example:
  • "/home/user/john/data.json"
-data-format
Specify the input data format.
Allowed values:
  • auto
    the data format is auto detected
  • json
  • xml
  • yaml
  • csv
Default: auto
-data-encoding
Set the encoding of the data file set by setDataFile.
Default: utf-8
Example:
  • Set to use Latin-2 encoding.
    "iso8859-2"
-data-ignore-undefined
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.
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-data-auto-escape
Auto escape HTML symbols in the input data before placing them into the output.
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-data-trim-blocks
Auto trim whitespace around each template command block.
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-data-options
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.
Examples:
  • Use semicolon to separate CSV data.
    "csv_delimiter=;"
  • Name the root of data rows and use the name in the template loop {% for row in rows %}...{% endfor %}.
    "data_root=rows"
  • Remove XML root so it the HTML template can be more simple.
    "xml_remove_root=1"

Miscellaneous

-debug-log
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.
Allowed values:
  • true, 1 or on
  • false, 0 or off
Default: False
-tag
Tag the conversion with a custom value. The tag is used in conversion statistics. A value longer than 32 characters is cut off.
Example:
  • "client-1234"
-http-proxy
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.
Constraint:
  • The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
Examples:
  • "myproxy.com:8080"
  • "113.25.84.10:33333"
-https-proxy
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.
Constraint:
  • The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
Examples:
  • "myproxy.com:443"
  • "113.25.84.10:44333"
-client-certificate
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.
Constraint:
  • The file must exist and not be empty.
Example:
  • "/home/user/john/pdfcrowd.crt"
-client-certificate-password
A password for PKCS12 file with a client certificate if it is needed.
Example:
  • "123456"

Tweaks

Expert options for fine-tuning output.

-max-loading-time
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.
Availability: API client >= 5.15.0, converter >= 20.10. See versioning.
Constraint:
  • The value must be in the range 10-30.