Free HTML to PDF API: convert HTML or a URL with one request

Request formats, code examples, settings, limits and error codes for the HTML to PDF API.

Updated · 5 min read

The same engine behind the converter is available as a simple HTTP API. There is no key or account: send HTML or a URL, receive a PDF. It’s rate limited and designed for light, occasional use such as scripts, prototypes and small internal tools.

Endpoints

EndpointBody
POST /api/convert/htmlJSON { "html": "…", "settings": {…} }
POST /api/convert/urlJSON { "url": "https://…", "settings": {…} }
POST /api/convert/fileMultipart form with one file (.html or .htm) and optional settings JSON

A successful response is the PDF itself, with Content-Type: application/pdf.

curl

curl -X POST https://htmltopdf.online/api/convert/html \
  -H "Content-Type: application/json" \
  -d '{"html":"<h1>Hello</h1><p>From the API.</p>"}' \
  -o hello.pdf

curl -X POST https://htmltopdf.online/api/convert/url \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com","settings":{"landscape":true}}' \
  -o page.pdf

curl -X POST https://htmltopdf.online/api/convert/file \
  -F "[email protected];type=text/html" \
  -F 'settings={"paper":"Letter","marginMm":15}' \
  -o invoice.pdf

JavaScript (Node 18+)

import { writeFile } from "node:fs/promises";

const response = await fetch("https://htmltopdf.online/api/convert/html", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ html: "<h1>Report</h1>", settings: { paper: "A4" } }),
});
if (!response.ok) throw new Error((await response.json()).error.message);
await writeFile("report.pdf", Buffer.from(await response.arrayBuffer()));

Python

import requests

response = requests.post(
    "https://htmltopdf.online/api/convert/html",
    json={"html": "<h1>Report</h1>", "settings": {"paper": "A4", "marginMm": 12}},
    timeout=60,
)
response.raise_for_status()
open("report.pdf", "wb").write(response.content)

Settings

FieldValuesDefault
paper"A4", "Letter", "Legal""A4"
landscapetrue or falsefalse
marginMm0 to 50, applied to every side10
printBackgroundtrue or falsetrue

Missing fields use the defaults. Unknown fields are rejected, so typos surface as errors instead of being ignored.

Limits

  • HTML up to 2 MiB (UTF-8); the whole request up to 3 MiB.
  • PDFs up to 100 pages and 20 MiB. Larger documents are rejected, never truncated.
  • 45 seconds per request.
  • 10 conversions per minute per client, and a small number at the same time across the service. Busy or rate-limited requests receive 429 with a Retry-After header.
  • URLs must be public http on port 80 or https on port 443.

Errors

Errors return JSON such as { "error": { "code": "URL_NOT_ALLOWED", "message": "…" } }.

StatusMeaning
400Invalid input, settings or a URL that isn’t allowed
413Input or PDF too large, or more than 100 pages
415Wrong content type or file type
429Rate limited or busy; wait for Retry-After seconds
502The page or one of its resources failed to load or render
503The PDF engine is temporarily unavailable
504Conversion took too long

Good to know

  • Requests from other websites’ browser code are refused; call the API from a server or script.
  • Documents aren’t saved to persistent storage. Don’t send passwords, signed URLs or sensitive private documents.
  • The API is free and has no uptime guarantee. For high-volume or business-critical workloads, run your own converter.