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.
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
| Endpoint | Body |
|---|---|
POST /api/convert/html | JSON { "html": "…", "settings": {…} } |
POST /api/convert/url | JSON { "url": "https://…", "settings": {…} } |
POST /api/convert/file | Multipart 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.pdfJavaScript (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
| Field | Values | Default |
|---|---|---|
paper | "A4", "Letter", "Legal" | "A4" |
landscape | true or false | false |
marginMm | 0 to 50, applied to every side | 10 |
printBackground | true or false | true |
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
429with aRetry-Afterheader. - URLs must be public
httpon port 80 orhttpson port 443.
Errors
Errors return JSON such as { "error": { "code": "URL_NOT_ALLOWED", "message": "…" } }.
| Status | Meaning |
|---|---|
| 400 | Invalid input, settings or a URL that isn’t allowed |
| 413 | Input or PDF too large, or more than 100 pages |
| 415 | Wrong content type or file type |
| 429 | Rate limited or busy; wait for Retry-After seconds |
| 502 | The page or one of its resources failed to load or render |
| 503 | The PDF engine is temporarily unavailable |
| 504 | Conversion 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.