HTML to PDF API
Turn HTML or a URL into a PDF with one request
Send HTML or a URL and get a PDF back right away. Built for receipts, quotes, reports and dashboards, with full Thai text support.
curl -X POST https://YOUR_HOST/v1/pdf \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"html":"<h1>Receipt</h1><p>Total paid: $15.00</p>","format":"A4"}' \
--output invoice.pdfWhy us
Built for production
Pay only for what works
Quota is counted only after a PDF is created successfully. Invalid requests and failed renders are never counted.
We do not store your files
Your HTML and PDFs are never saved to our database. We keep only monthly usage counts, key hashes, Stripe payment reference IDs, and the email and IP address used when a free key is requested.
Thai text supported
Tested with the Sarabun font: Thai characters, vowels and tone marks render correctly in the PDF. We recommend including a Thai web font from Google Fonts in your HTML for consistent results.
API reference
API documentation
Authentication
Send your key in the Authorization: Bearer lk_... or x-api-key: lk_... header on every request.
POST /v1/pdf
Send JSON and receive a PDF (application/pdf) back. Set Content-Type: application/json.
| Parameter | Type | Default | Description |
|---|---|---|---|
html | string | - | The HTML to convert. Send exactly one of html or url. |
url | string | - | An http(s) page that the browser opens and prints to PDF. |
format | string | A4 | A0-A6, Letter, Legal, Tabloid, Ledger (case-insensitive) |
landscape | boolean | false | true = landscape orientation |
printBackground | boolean | true | Print background colors and images |
preferCSSPageSize | boolean | false | Use the page size from CSS @page |
scale | number | 1 | 0.1 to 2 |
margin | object | - | Set top, right, bottom, left as strings, e.g. "10mm" |
pageRanges | string | - | e.g. "1-3" |
headerTemplate, footerTemplate | string | - | HTML for the page header/footer (setting either one enables both) |
waitUntil | string | load | load, domcontentloaded or networkidle (30-second timeout) |
viewport | object | - | Browser window size before printing, e.g. {"width":1280,"height":800} (200 to 3840 px). Useful for URLs whose layout depends on screen width. |
css | string | - | CSS injected into the page before printing (up to 100,000 characters), e.g. to turn off page animations. |
emulateMediaType | string | - | screen or print: the media type used while rendering. |
waitForTimeout | number | 0 | Wait (milliseconds) after the page loads, 0 to 10000. For pages with animations. |
Code examples
curl -X POST https://YOUR_HOST/v1/pdf \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"html":"<h1>Hello</h1>","format":"A4"}' \
--output out.pdf
const res = await fetch("https://YOUR_HOST/v1/pdf", {
method: "POST",
headers: { Authorization: "Bearer YOUR_API_KEY", "Content-Type": "application/json" },
body: JSON.stringify({ html: "<h1>Hello</h1>", format: "A4" }),
});
if (!res.ok) throw new Error(JSON.stringify(await res.json()));
require("fs").writeFileSync("out.pdf", Buffer.from(await res.arrayBuffer()));
import requests
r = requests.post("https://YOUR_HOST/v1/pdf",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"html": "<h1>Hello</h1>", "format": "A4"})
r.raise_for_status()
open("out.pdf", "wb").write(r.content)Response headers: x-leafkiln-used (files used this month) and x-leafkiln-limit (monthly quota)
GET /v1/usage
Shows the plan and quota for your key. Calls to this endpoint do not count as usage.
{ "plan": "free", "used": 2, "limit": 100, "remaining": 98 }Error codes
| HTTP | code | Meaning and fix |
|---|---|---|
| 400 | bad_request | Invalid JSON or parameters. See error.message. |
| 401 | unauthorized | Missing, invalid or revoked key. |
| 402 | quota_exceeded | Monthly quota used up. It resets at the start of each month (UTC), or upgrade your plan. |
| 413 | too_large | Request body exceeds 6 MB. |
| 422 / 502 | render_failed | The PDF could not be created. Check your HTML/URL and retry. Not counted against your quota. |
| 503 | capacity | Rendering capacity is temporarily full. Wait a moment and retry. |
Interactive sandbox
Try the API right here
Pricing
Monthly plans
Pay, then receive your API key instantly on the next page
Get started
Get a free key: 100 files/month
Your key is shown only once, so copy it somewhere safe. If you lose it, you can request a new one by email.