HTML to Image / Command Line Examples

This page contains various examples of using the HTML to Image API in Command Line. The examples are complete and fully functional. Read more about how to convert HTML to Image in Command Line.

Basic examples
Template rendering examples

Basic examples

Webpage to PNG file

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

HTML file to PNG file

html2image -user-name "demo" -api-key "ce544b6ea52a5621fb9d55f8b542d14d" \
    -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 "ce544b6ea52a5621fb9d55f8b542d14d" \
    -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 "ce544b6ea52a5621fb9d55f8b542d14d" \
    -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 "ce544b6ea52a5621fb9d55f8b542d14d" \
    -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 "ce544b6ea52a5621fb9d55f8b542d14d" \
    -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 "ce544b6ea52a5621fb9d55f8b542d14d" \
    -output-format "png" \
    -data-string "$(echo -e "name,product
World,Pdfcrowd API")" - > "output.pdf"