curl3 min read · June 8, 2026

Generate a PDF from HTML Using curl in 30 Seconds

The quickest way to test HTML to PDF conversion: a single curl command. Works from any terminal, CI pipeline, or shell script.

Before you wire up a library or SDK, it's useful to confirm the API works end-to-end with a single terminal command. curl is the fastest way to do that — no language runtime, no package manager, just a shell.

Convert HTML to PDF

Replace YOUR_API_KEY with the key from your dashboard:

Terminalbash
curl -X POST https://platform.htmltopdfapi.co/api/v1/pdf/generate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/pdf" \
  -d '{"html":"<h1>Hello World</h1>","paper_size":"a4","orientation":"portrait"}' \
  --output document.pdf

Convert a URL to PDF

Terminalbash
curl -X POST https://platform.htmltopdfapi.co/api/v1/pdf/generate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/pdf" \
  -d '{"url":"https://example.com","paper_size":"a4"}' \
  --output page.pdf

Use in a Shell Script

Useful for CI pipelines, report generation scripts, or any automation that needs PDFs:

generate-report.shbash
#!/usr/bin/env bash
set -euo pipefail

HTML=$(cat report.html)

curl -s -X POST https://platform.htmltopdfapi.co/api/v1/pdf/generate \
  -H "Authorization: Bearer $HTMLTOPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/pdf" \
  --data-binary "$(jq -n --arg html "$HTML" '{html:$html,paper_size:"a4"}')" \
  --output "report-$(date +%Y%m%d).pdf"

echo "Report saved."

Checking for Errors

Add -w "%{http_code}" to print the HTTP status code after the request. A 200 means success; a 401 means check your API key; a 422 means check your request body.

check statusbash
STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
  https://platform.htmltopdfapi.co/api/v1/pdf/generate \
  -H "Authorization: Bearer $HTMLTOPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html":"<p>test</p>","paper_size":"a4"}')

echo "HTTP $STATUS"