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

HTML to PDF - 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 PDF file

html2pdf -user-name "username" -api-key "apikey" \
    "http://www.example.com" > example.pdf

Convert a local HTML file to a PDF file

html2pdf -user-name "username" -api-key "apikey" \
    "/path/to/MyLayout.html" > MyLayout.pdf

Convert a string containing HTML to a PDF file

echo -n "<html><body><h1>Hello World!</h1></body></html>" | \
    html2pdf -user-name "username" -api-key "apikey" - > HelloWorld.pdf

html2pdf Manual

Conversion from HTML to PDF.

usage: html2pdf [options] source

Conversion from HTML to PDF.

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.
  -page-size PAGE_SIZE  Set the output page size. Allowed values are A2, A3,
                        A4, A5, A6, Letter.
  -page-width PAGE_WIDTH
                        Set the output page width. Can be specified in inches
                        (in), millimeters (mm), centimeters (cm), or points
                        (pt).
  -page-height PAGE_HEIGHT
                        Set the output page height. Use -1 for a single page
                        PDF. Can be -1 or specified in inches (in),
                        millimeters (mm), centimeters (cm), or points (pt).
  -page-dimensions PAGE_DIMENSIONS
                        Set the output page dimensions. PAGE_DIMENSIONS must
                        contain 2 values separated by a semicolon. Set the
                        output page width. Can be specified in inches (in),
                        millimeters (mm), centimeters (cm), or points (pt).
                        Set the output page height. Use -1 for a single page
                        PDF. Can be -1 or specified in inches (in),
                        millimeters (mm), centimeters (cm), or points (pt).
  -orientation ORIENTATION
                        Set the output page orientation. Allowed values are
                        landscape, portrait.
  -margin-top MARGIN_TOP
                        Set the output page top margin. Can be specified in
                        inches (in), millimeters (mm), centimeters (cm), or
                        points (pt).
  -margin-right MARGIN_RIGHT
                        Set the output page right margin. Can be specified in
                        inches (in), millimeters (mm), centimeters (cm), or
                        points (pt).
  -margin-bottom MARGIN_BOTTOM
                        Set the output page bottom margin. Can be specified in
                        inches (in), millimeters (mm), centimeters (cm), or
                        points (pt).
  -margin-left MARGIN_LEFT
                        Set the output page left margin. Can be specified in
                        inches (in), millimeters (mm), centimeters (cm), or
                        points (pt).
  -no-margins           Disable margins.
  -page-margins PAGE_MARGINS
                        Set the output page margins. PAGE_MARGINS must contain
                        4 values separated by a semicolon. Set the output page
                        top margin. Set the output page right margin. Set the
                        output page bottom margin. Set the output page left
                        margin. All values can be specified in inches (in),
                        millimeters (mm), centimeters (cm), or points (pt).
  -header-url HEADER_URL
                        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 Arabic
                        numerals are used by default. Roman numerals can be
                        generated by the roman and roman-lowercase values
                        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>http://example.com</span> 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.com'>Link to source</a> href-and-
                        content - the URL is set to the href attribute and to
                        the content Example: <a class='pdfcrowd-source-url'
                        data-pdfcrowd-placement='href-and-content'></a> will
                        produce <a
                        href='http://example.com'>http://example.com</a> The
                        supported protocols are http:// and https://.
  -header-html HEADER_HTML
                        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 Arabic numerals are used by
                        default. Roman numerals can be generated by the roman
                        and roman-lowercase values 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>http://example.com</span> 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.com'>Link to source</a> href-and-
                        content - the URL is set to the href attribute and to
                        the content Example: <a class='pdfcrowd-source-url'
                        data-pdfcrowd-placement='href-and-content'></a> will
                        produce <a
                        href='http://example.com'>http://example.com</a> The
                        string must not be empty.
  -header-height HEADER_HEIGHT
                        Set the header height. Can be specified in inches
                        (in), millimeters (mm), centimeters (cm), or points
                        (pt).
  -footer-url FOOTER_URL
                        Load an HTML code from the specified URL and use it as
                        the page footer. 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 Arabic
                        numerals are used by default. Roman numerals can be
                        generated by the roman and roman-lowercase values
                        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>http://example.com</span> 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.com'>Link to source</a> href-and-
                        content - the URL is set to the href attribute and to
                        the content Example: <a class='pdfcrowd-source-url'
                        data-pdfcrowd-placement='href-and-content'></a> will
                        produce <a
                        href='http://example.com'>http://example.com</a> The
                        supported protocols are http:// and https://.
  -footer-html FOOTER_HTML
                        Use the specified HTML as the page footer. 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 Arabic numerals are used by
                        default. Roman numerals can be generated by the roman
                        and roman-lowercase values 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>http://example.com</span> 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.com'>Link to source</a> href-and-
                        content - the URL is set to the href attribute and to
                        the content Example: <a class='pdfcrowd-source-url'
                        data-pdfcrowd-placement='href-and-content'></a> will
                        produce <a
                        href='http://example.com'>http://example.com</a> The
                        string must not be empty.
  -footer-height FOOTER_HEIGHT
                        Set the footer height. Can be specified in inches
                        (in), millimeters (mm), centimeters (cm), or points
                        (pt).
  -print-page-range PRINT_PAGE_RANGE
                        Set the page range to print. A comma seperated list of
                        page numbers or ranges.
  -page-watermark PAGE_WATERMARK
                        Apply the first page of the watermark PDF to every
                        page of the output PDF. The file path to a local
                        watermark PDF file. The file must exist and not be
                        empty.
  -multipage-watermark MULTIPAGE_WATERMARK
                        Apply each page of the specified watermark PDF to the
                        corresponding page of the output PDF. The file path to
                        a local watermark PDF file. The file must exist and
                        not be empty.
  -page-background PAGE_BACKGROUND
                        Apply the first page of the specified PDF to the
                        background of every page of the output PDF. The file
                        path to a local background PDF file. The file must
                        exist and not be empty.
  -multipage-background MULTIPAGE_BACKGROUND
                        Apply each page of the specified PDF to the background
                        of the corresponding page of the output PDF. The file
                        path to a local background PDF file. The file must
                        exist and not be empty.
  -exclude-header-on-pages EXCLUDE_HEADER_ON_PAGES
                        The page header is not printed on the specified 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 seperated
                        list of page numbers.
  -exclude-footer-on-pages EXCLUDE_FOOTER_ON_PAGES
                        The page footer is not printed on the specified 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 seperated
                        list of page numbers.
  -page-numbering-offset PAGE_NUMBERING_OFFSET
                        Set an offset between physical and logical page
                        numbers. Integer specifying page offset.
  -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.
  -viewport VIEWPORT    Set the viewport size. The viewport is the user's
                        visible area of the page. VIEWPORT must contain 2
                        values separated by a semicolon. Set the viewport
                        width in pixels. The viewport is the user's visible
                        area of the page. The value must be in a range
                        96-7680. Set the viewport height in pixels. The
                        viewport is the user's visible area of the page. Must
                        be a positive integer number.
  -rendering-mode RENDERING_MODE
                        Sets the rendering mode. The rendering mode. Allowed
                        values are default, viewport.
  -scale-factor SCALE_FACTOR
                        Set the scaling factor (zoom) for the main page area.
                        The scale factor. The value must be in a range 10-500.
  -header-footer-scale-factor HEADER_FOOTER_SCALE_FACTOR
                        Set the scaling factor (zoom) for the header and
                        footer. The scale factor. The value must be in a range
                        10-500.
  -linearize            Create linearized PDF. This is also known as Fast Web
                        View.
  -encrypt              Encrypt the PDF. This prevents search engines from
                        indexing the contents.
  -user-password USER_PASSWORD
                        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. The user password.
  -owner-password OWNER_PASSWORD
                        Protect the PDF with an owner password. Supplying an
                        owner password grants unlimited access to the PDF
                        including changing the passwords and access
                        permissions. The owner password.
  -no-print             Disallow printing of the output PDF.
  -no-modify            Disallow modification of the ouput PDF.
  -no-copy              Disallow text and graphics extraction from the output
                        PDF.
  -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