Convert HTML to PDF with cURL

Convert HTML to PDF from the command line using cURL. Perfect for quick testing, shell scripts, and automation.

Quick Start

curl -X POST https://html2pdfapi.com/render \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html": "<h1>Hello World</h1>", "format": "pdf"}' \
  --output output.pdf

Convert URL to PDF

curl -X POST https://html2pdfapi.com/render \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "format": "pdf",
    "options": {
      "format": "A4",
      "printBackground": true
    }
  }' \
  --output webpage.pdf

Take Screenshot

curl -X POST https://html2pdfapi.com/render \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "format": "png",
    "options": {
      "width": 1920,
      "height": 1080
    }
  }' \
  --output screenshot.png

Read HTML from File

# Read HTML from file
curl -X POST https://html2pdfapi.com/render \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"html\": $(cat template.html | jq -Rs .), \"format\": \"pdf\"}" \
  --output output.pdf

Available Options

OptionTypeDescription
formatstringOutput format: 'pdf', 'png', 'jpeg', 'webp'
htmlstringHTML content to convert
urlstringURL to convert
options.formatstringPage size: 'A4', 'Letter', etc.
options.landscapebooleanLandscape orientation
options.printBackgroundbooleanInclude background colors/images

Other Integrations

Node.js Python PHP Ruby Go n8n

See Use Cases

Get Your API Key

Sign up and start converting HTML to PDF from the command line.