For developers
HTML to PDF API
Send HTML, a public URL or an .html file in one POST request and get a PDF back. Authenticate with an API key, set the page size in pixels, and handle a small, predictable JSON response.
curl -X POST https://www.cheap-pdf.com/generate-pdf-public \
-F "apikey=YOUR_API_KEY" \
-F "filename=hello.pdf" \
-F "width=800" \
-F "height=1000" \
--form-string "fileorhtmlorurl=<h1>Hello from CheapPDF</h1>" \
-o response.json
# The PDF is returned base64-encoded inside the JSON:
jq -r '.data.base64_pdf' response.json | base64 --decode > hello.pdf<?php
$ch = curl_init('https://www.cheap-pdf.com/generate-pdf-public');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_POSTFIELDS => [
'apikey' => getenv('CHEAPPDF_API_KEY'),
'filename' => 'hello.pdf',
'width' => 800,
'height' => 1000,
'fileorhtmlorurl' => '<h1>Hello from CheapPDF</h1>',
],
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
$result = json_decode($body, true);
if ($status !== 200 || empty($result['success'])) {
throw new RuntimeException($result['message'] ?? "Conversion failed (HTTP $status)");
}
file_put_contents('hello.pdf', base64_decode($result['data']['base64_pdf']));import base64, os, requests
resp = requests.post(
"https://www.cheap-pdf.com/generate-pdf-public",
data={
"apikey": os.environ["CHEAPPDF_API_KEY"],
"filename": "hello.pdf",
"width": 800,
"height": 1000,
"fileorhtmlorurl": "<h1>Hello from CheapPDF</h1>",
},
timeout=60,
)
result = resp.json()
if resp.status_code != 200 or not result.get("success"):
raise RuntimeError(result.get("message", f"Conversion failed (HTTP {resp.status_code})"))
with open("hello.pdf", "wb") as f:
f.write(base64.b64decode(result["data"]["base64_pdf"]))// Node.js 18+ (built-in fetch and FormData)
import { writeFile } from "node:fs/promises";
const form = new FormData();
form.append("apikey", process.env.CHEAPPDF_API_KEY);
form.append("filename", "hello.pdf");
form.append("width", "800");
form.append("height", "1000");
form.append("fileorhtmlorurl", "<h1>Hello from CheapPDF</h1>");
const res = await fetch("https://www.cheap-pdf.com/generate-pdf-public", {
method: "POST",
body: form,
signal: AbortSignal.timeout(60_000),
});
const result = await res.json();
if (!res.ok || !result.success) {
throw new Error(result.message ?? `Conversion failed (HTTP ${res.status})`);
}
await writeFile("hello.pdf", Buffer.from(result.data.base64_pdf, "base64"));Request and response
Send a POST to https://www.cheap-pdf.com/generate-pdf-public. Both multipart/form-data and URL-encoded bodies are accepted.
| Field | Required | Description |
|---|---|---|
apikey | Yes | Your API key. Keep it on the server. |
fileorhtmlorurl | Yes | Raw HTML, a public URL, or an uploaded .html file (up to 5 MB). |
filename | Yes | Name for the PDF, for example invoice-1042.pdf. |
width, height | No | Page size in pixels. |
landscape, printBackground | No | Orientation and background printing. |
Success response (HTTP 200)
{
"success": true,
"data": {
"status": "success",
"code": 200,
"message": "PDF generated successfully",
"base64_pdf": "JVBERi0xLjQK...",
"filename": "hello.pdf"
}
}The PDF is delivered base64-encoded in data.base64_pdf. Decode it and write the bytes to a file, as in the examples above.
Error response
{
"success": false,
"message": "Invalid API key, please get a new API key from the dashboard",
"error": "invalid_api_key"
}Supported input types
Raw HTML
Pass a complete HTML document (or fragment) as the fileorhtmlorurl field. Ideal for server-rendered invoices and reports.
Public URL
Pass an http(s) address. Pages must be publicly reachable; localhost, private networks and non-standard ports are rejected.
Uploaded .html file
Upload a single self-contained file as fileorhtmlorurl in a multipart request. Maximum 5 MB.
Authentication and integration workflow
Create an API key
Sign up on the Get Started page. You can start on the free plan without a credit card.
Call from your server
Store the key in an environment variable and send it in the
apikeyfield. Never put it in browser-side code.Decode and store the PDF
Read
data.base64_pdf, decode it, and save or stream the bytes. Checksuccessfirst.
Error handling, timeouts and retries
| HTTP status | error value | Meaning and what to do |
|---|---|---|
| 400 | api_key_required | The apikey field is missing. Add it. |
| 400 | invalid_api_key | The key is not recognised. Copy it again from your dashboard. |
| 400 | free_plan_limit_reached | The daily free allowance is used up. Upgrade, or try again tomorrow. |
| 400 | subscription_inactive | The subscription is not active. Renew it to continue. |
| 400 | unsafe_url | The URL targets a private or unsupported address. Use a public http(s) URL. |
| 400 | No error code | The input was empty, not valid HTML or URL, or an uploaded file was not .html or was over 5 MB. |
| 405 | — | The request was not a POST. |
| 5xx / upstream | — | Rendering failed upstream. The response includes the upstream message when available. |
Retry guidance. Do not retry 400 responses, because the same request will fail again. For 5xx responses or network timeouts, retry a small number of times with exponential backoff, and set a client timeout (the examples use 60 seconds). Per-plan timeouts and request rate limits are not published, so build your integration to tolerate slow responses.
Integration guides by language
Pricing and usage limits
Free
$0
- 10 conversions per day
- HTML file uploads up to 5 MB
- No credit card required
Premium
$5 / month
- Unlimited conversions, as described on our pricing page
- API key access and priority support
- Cancel any time
HTML to PDF API FAQ
What is the API endpoint?
POST https://www.cheap-pdf.com/generate-pdf-public with the fields apikey, fileorhtmlorurl and filename, plus optional width and height in pixels.
What does the API return?
A JSON object. On success, data.base64_pdf contains the PDF encoded as base64 and data.filename holds the file name. On failure, success is false and message explains why.
How do I send HTML from cURL?
Use --form-string for the HTML field. With -F, curl treats a value that starts with < as a file path to read.
Is there an SDK?
No official SDK is published. The API is a single HTTP request, so any HTTP client works, and the language guides show complete examples.
Does the API support webhooks?
No webhook feature is currently documented. Conversions are synchronous: the PDF comes back in the response.
Can I convert pages behind a login?
Authenticated pages are not supported. Render the page to HTML on your server and send the HTML instead.
Start generating PDFs with the API
Create a free API key and make your first conversion in a few minutes.