Important: This document is for the beta version of the new Pdfcrowd API. Use this documentation for the stable API version.

HTML to Image - Command Line Tool

Installation

You can install the application from PyPI
 $ pip install pdfcrowd

You can learn more install options here.

The package installs tools for all Pdfcrowd converters.

Authentication

Authentication is needed in order to use the Pdfcrowd API. The credentials used for accessing the API are your Pdfcrowd username and the API key. You can find the API key in your account page.

Getting Started

Convert a web page to a PNG file

html2image -user-name "username" -api-key "apikey" \
    -output-format "png" \
    "http://www.example.com" > example.png

Convert a local HTML file to a PNG file

html2image -user-name "username" -api-key "apikey" \
    -output-format "png" \
    "/path/to/MyLayout.html" > MyLayout.png

Convert a string containing HTML to a PNG file

echo -n "<html><body><h1>Hello World!</h1></body></html>" | \
    html2image -user-name "username" -api-key "apikey" \
    -output-format "png" - > HelloWorld.png

html2image Manual

Conversion from HTML to image.

usage: html2image [options] source

Conversion from HTML to image.

positional arguments:
  source                Source to be converted. It can be URL, path to a local
                        file or '-' to use stdin as an input text.

optional arguments:
  -user-name USER_NAME  Your user name at pdfcrowd.com.
  -api-key API_KEY      Your API key at pdfcrowd.com.
  -output-format OUTPUT_FORMAT
                        The format of the output file. Allowed values are png,
                        jpg, gif, tiff, bmp, ico, ppm, pgm, pbm, pnm, psb,
                        pct, ras, tga, sgi, sun, webp.
  -no-background        Do not print the background graphics.
  -disable-javascript   Do not execute JavaScript.
  -disable-image-loading
                        Do not load images.
  -disable-remote-fonts
                        Disable loading fonts from remote sources.
  -block-ads            Try to block ads. Enabling this option can produce
                        smaller output and speed up the conversion.
  -default-encoding DEFAULT_ENCODING
                        Set the default HTML content text encoding. The text
                        encoding of the HTML content.
  -http-auth HTTP_AUTH  Set the HTTP authentication. HTTP_AUTH must contain 2
                        values separated by a semicolon. Set the HTTP
                        authentication user name. Set the HTTP authentication
                        password.
  -use-print-media      Use the print version of the page if available (@media
                        print).
  -no-xpdfcrowd-header  Do not send the X-Pdfcrowd HTTP header in Pdfcrowd
                        HTTP requests.
  -cookies COOKIES      Set cookies that are sent in Pdfcrowd HTTP requests.
                        The cookie string.
  -verify-ssl-certificates
                        Do not allow insecure HTTPS connections.
  -fail-on-main-url-error
                        Abort the conversion if the main URL HTTP status code
                        is greater than or equal to 400.
  -fail-on-any-url-error
                        Abort the conversion if any of the sub-request HTTP
                        status code is greater than or equal to 400.
  -custom-javascript CUSTOM_JAVASCRIPT
                        Run a custom JavaScript after the document is loaded.
                        The script is intended for post-load DOM manipulation
                        (add/remove elements, update CSS, ...). String
                        containing a JavaScript code. The string must not be
                        empty.
  -custom-http-header CUSTOM_HTTP_HEADER
                        Set a custom HTTP header that is sent in Pdfcrowd HTTP
                        requests. A string containing the header name and
                        value separated by a colon.
  -javascript-delay JAVASCRIPT_DELAY
                        Wait the specified number of milliseconds to finish
                        all JavaScript after the document is loaded. The
                        maximum value is determined by your API license. The
                        number of milliseconds to wait. Must be a positive
                        integer number or 0.
  -element-to-convert ELEMENT_TO_CONVERT
                        Convert only the specified element 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.
                        One or more CSS selectors separated by commas. The
                        string must not be empty.
  -element-to-convert-mode ELEMENT_TO_CONVERT_MODE
                        Specify the DOM handling when only a part of the
                        document is converted. Allowed values are cut-out,
                        remove-siblings, hide-siblings.
  -wait-for-element WAIT_FOR_ELEMENT
                        Wait for the specified element in a source document.
                        The element is specified by one or more CSS selectors.
                        If the element is not found, the conversion fails. One
                        or more CSS selectors separated by commas. The string
                        must not be empty.
  -screenshot-width SCREENSHOT_WIDTH
                        Set the output image width in pixels. The value must
                        be in a range 96-7680.
  -screenshot-height SCREENSHOT_HEIGHT
                        Set the output image height in pixels. If it's not
                        specified, actual document height is used. Must be a
                        positive integer number.
  -debug-log            Turn on the debug logging.
  -use-http             Specifies if the client communicates over HTTP or
                        HTTPS with Pdfcrowd API.
  -user-agent USER_AGENT
                        Set a custom user agent HTTP header. It can be usefull
                        if you are behind some proxy or firewall. The user
                        agent string.
  -proxy PROXY          Specifies an HTTP proxy that the API client library
                        will use to connect to the internet. PROXY must
                        contain 4 values separated by a semicolon. The proxy
                        hostname. The proxy port. The username. The password.
  -retry-count RETRY_COUNT
                        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. Number of retries wanted.

produced by: www.pdfcrowd.com