HTML to Image HTTP POST Examples

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

Basic examples
Template rendering examples

Basic examples

Webpage to PNG file

curl -f -u "demo:ce544b6ea52a5621fb9d55f8b542d14d" \
    -o "example.png" \
    -F "output_format=png" \
    -F "url=http://www.example.com" \
    https://api.pdfcrowd.com/convert/24.04/

HTML file to PNG file

curl -f -u "demo:ce544b6ea52a5621fb9d55f8b542d14d" \
    -o "MyLayout.png" \
    -F "output_format=png" \
    -F "file=@/path/to/MyLayout.html" \
    https://api.pdfcrowd.com/convert/24.04/

HTML string to PNG file

curl -f -u "demo:ce544b6ea52a5621fb9d55f8b542d14d" \
    -o "HelloWorld.png" \
    -F "output_format=png" \
    --form-string "text=<html><body><h1>Hello World!</h1></body></html>" \
    https://api.pdfcrowd.com/convert/24.04/

# or read HTML from a pipe
html_producer | curl -u "demo:ce544b6ea52a5621fb9d55f8b542d14d" \
    -o "HelloWorld.png" \
    -F "output_format=png" \
    -F "text=<-" \
    https://api.pdfcrowd.com/convert/24.04/

Template rendering examples

Create Image from JSON data

curl -f -u "demo:ce544b6ea52a5621fb9d55f8b542d14d" \
    -o "output.pdf" \
    -F "output_format=png" \
    --form-string "data_string={
            \"name\": \"World\",
            \"product\": \"Pdfcrowd API\"
        }" \
    --form-string "text=Hello {{ name }} from {{ product }}" \
    https://api.pdfcrowd.com/convert/24.04/

# or read HTML from a pipe
html_producer | curl -u "demo:ce544b6ea52a5621fb9d55f8b542d14d" \
    -o "output.pdf" \
    -F "output_format=png" \
    --form-string "data_string={
            \"name\": \"World\",
            \"product\": \"Pdfcrowd API\"
        }" \
    -F "text=<-" \
    https://api.pdfcrowd.com/convert/24.04/

Create Image from XML data

curl -f -u "demo:ce544b6ea52a5621fb9d55f8b542d14d" \
    -o "output.pdf" \
    -F "output_format=png" \
    --form-string "data_string=<?xml version=\"1.0\" encoding=\"UTF-8\"?>
        <data>
          <name>World</name>
          <product>Pdfcrowd API</product>
        </data>" \
    --form-string "text=Hello {{ data.name }} from {{ data.product }}" \
    https://api.pdfcrowd.com/convert/24.04/

# or read HTML from a pipe
html_producer | curl -u "demo:ce544b6ea52a5621fb9d55f8b542d14d" \
    -o "output.pdf" \
    -F "output_format=png" \
    --form-string "data_string=<?xml version=\"1.0\" encoding=\"UTF-8\"?>
        <data>
          <name>World</name>
          <product>Pdfcrowd API</product>
        </data>" \
    -F "text=<-" \
    https://api.pdfcrowd.com/convert/24.04/

Create Image from YAML data

curl -f -u "demo:ce544b6ea52a5621fb9d55f8b542d14d" \
    -o "output.pdf" \
    -F "output_format=png" \
    -F "data_string=name: World
product: Pdfcrowd API" \
    --form-string "text=Hello {{ name }} from {{ product }}" \
    https://api.pdfcrowd.com/convert/24.04/

# or read HTML from a pipe
html_producer | curl -u "demo:ce544b6ea52a5621fb9d55f8b542d14d" \
    -o "output.pdf" \
    -F "output_format=png" \
    -F "data_string=name: World
product: Pdfcrowd API" \
    -F "text=<-" \
    https://api.pdfcrowd.com/convert/24.04/

Create Image from CSV data

curl -f -u "demo:ce544b6ea52a5621fb9d55f8b542d14d" \
    -o "output.pdf" \
    -F "output_format=png" \
    -F "data_string=name,product
World,Pdfcrowd API" \
    --form-string "text=Hello {{ name }} from {{ product }}" \
    https://api.pdfcrowd.com/convert/24.04/

# or read HTML from a pipe
html_producer | curl -u "demo:ce544b6ea52a5621fb9d55f8b542d14d" \
    -o "output.pdf" \
    -F "output_format=png" \
    -F "data_string=name,product
World,Pdfcrowd API" \
    -F "text=<-" \
    https://api.pdfcrowd.com/convert/24.04/