HTML to Image Command Line Code Examples

These command line examples show URL and HTML file conversion to PNG, JPEG, WebP, or GIF from scripts and terminals.

For installation, authentication, and the basic conversion flow, start with the HTML to Image in Command Line documentation.

Basic examples
Template rendering examples

Basic examples

Webpage to PNG file

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

HTML file to PNG file

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

HTML string to PNG file

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

Template rendering examples

Create Image from JSON data

echo -n "Hello {{ name }} from {{ product }}" | \
html2image -user-name "demo" -api-key "demo" \
    -output-format "png" \
    -data-string "$(echo -e "{
            \"name\": \"World\",
            \"product\": \"Pdfcrowd API\"
        }")" - > "output.pdf"

Create Image from XML data

echo -n "Hello {{ data.name }} from {{ data.product }}" | \
html2image -user-name "demo" -api-key "demo" \
    -output-format "png" \
    -data-string "$(echo -e "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
        <data>
          <name>World</name>
          <product>Pdfcrowd API</product>
        </data>")" - > "output.pdf"

Create Image from YAML data

echo -n "Hello {{ name }} from {{ product }}" | \
html2image -user-name "demo" -api-key "demo" \
    -output-format "png" \
    -data-string "$(echo -e "name: World
product: Pdfcrowd API")" - > "output.pdf"

Create Image from CSV data

echo -n "Hello {{ name }} from {{ product }}" | \
html2image -user-name "demo" -api-key "demo" \
    -output-format "png" \
    -data-string "$(echo -e "name,product
World,Pdfcrowd API")" - > "output.pdf"