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
- Create Image from JSON data
- Create Image from XML data
- Create Image from YAML data
- Create Image from CSV data
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"