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

Convert a web page to a PNG file

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

Convert a local HTML file to a PNG file

html2image -user-name "demo" -api-key "ce544b6ea52a5621fb9d55f8b542d14d" \
    -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 "demo" -api-key "ce544b6ea52a5621fb9d55f8b542d14d" \
    -output-format "png" - > "HelloWorld.png"

Advanced examples

Template rendering Examples

Create Image from JSON data

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

Create Image from XML data

echo -n "Hello {{ data.name }} from {{ data.product }}" | \
html2pdf -user-name "demo" -api-key "ce544b6ea52a5621fb9d55f8b542d14d" \
    -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 }}" | \
html2pdf -user-name "demo" -api-key "ce544b6ea52a5621fb9d55f8b542d14d" \
    -data-string "$(echo -e "name: World
product: Pdfcrowd API")" - > "output.pdf"

Create Image from CSV data

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