Convert HTML pages or raw markup to PDF via a simple HTTP API.
| Plan | Requests / month | Monthly | Yearly | Overage (per 1,000) |
|---|---|---|---|---|
| Free | 500 | $0 | $0 | None — requests stop once the limit is reached |
| Starter | 50,000 | $9.99 | $99.99 | $0.99 / 1,000 |
| Pro | 250,000 | $39.99 | $399.99 | $0.79 / 1,000 |
| Business | 1,000,000 | $99.99 | $999.99 | $0.49 / 1,000 |
The /pdf endpoint accepts a JSON body and returns raw PDF bytes (application/pdf).
All requests must include an Authorization: Bearer <token> header.
url field; Chrome fetches and renders the page.data field containing the HTML, base64-encoded.options object (see Print options below).| Field | Type | Default | Description |
|---|---|---|---|
| landscape | bool | false | Landscape orientation |
| displayHeaderFooter | bool | false | Show Chrome's default header/footer |
| printBackground | bool | true | Print background graphics and colors |
| scale | float | 1.0 | Page scale factor (0.1–2.0) |
| paperWidth | float | 8.27 | Paper width in inches (A4 default) |
| paperHeight | float | 11.69 | Paper height in inches (A4 default) |
| marginTop | float | 0.0 | Top margin in inches |
| marginBottom | float | 0.0 | Bottom margin in inches |
| marginLeft | float | 0.0 | Left margin in inches |
| marginRight | float | 0.0 | Right margin in inches |
| preferCSSPageSize | bool | false | Use @page CSS size instead of paperWidth/paperHeight |
# URL mode — render a public URL
curl -s -X POST https://htmlpdfs.com/pdf \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"url":"https://example.com"}' \
--output page.pdf
# Data mode — render inline HTML (base64-encoded)
HTML=$(echo -n '<h1>Hello PDF</h1><p>Generated from HTML.</p>' | base64)
curl -s -X POST https://htmlpdfs.com/pdf \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d "{\"data\":\"$HTML\"}" \
--output page.pdf
# With custom print options (A4 landscape, 0.5 inch margins)
curl -s -X POST https://htmlpdfs.com/pdf \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"url": "https://example.com",
"options": {
"landscape": true,
"printBackground": true,
"marginTop": 0.5,
"marginBottom": 0.5,
"marginLeft": 0.5,
"marginRight": 0.5
}
}' \
--output page.pdf
import base64
import requests
BASE_URL = "https://htmlpdfs.com"
TOKEN = "YOUR_TOKEN"
HEADERS = {"Authorization": f"Bearer {TOKEN}", "Content-Type": "application/json"}
# URL mode
resp = requests.post(f"{BASE_URL}/pdf", headers=HEADERS, json={"url": "https://example.com"})
resp.raise_for_status()
open("page.pdf", "wb").write(resp.content)
# Data mode
html = "<h1>Hello PDF</h1><p>Generated from HTML.</p>"
encoded = base64.b64encode(html.encode()).decode()
resp = requests.post(f"{BASE_URL}/pdf", headers=HEADERS, json={"data": encoded})
resp.raise_for_status()
open("page.pdf", "wb").write(resp.content)
# With options
resp = requests.post(f"{BASE_URL}/pdf", headers=HEADERS, json={
"url": "https://example.com",
"options": {
"landscape": True,
"printBackground": True,
"paperWidth": 11.69, # A4 landscape width
"paperHeight": 8.27, # A4 landscape height
"marginTop": 0.5,
"marginBottom": 0.5,
"marginLeft": 0.5,
"marginRight": 0.5,
},
})
resp.raise_for_status()
open("page.pdf", "wb").write(resp.content)
const fs = require("fs");
const BASE_URL = "https://htmlpdfs.com";
const TOKEN = "YOUR_TOKEN";
const headers = { Authorization: `Bearer ${TOKEN}`, "Content-Type": "application/json" };
async function htmlToPdf(body, outFile) {
const res = await fetch(`${BASE_URL}/pdf`, { method: "POST", headers, body: JSON.stringify(body) });
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
fs.writeFileSync(outFile, Buffer.from(await res.arrayBuffer()));
console.log("Saved", outFile);
}
// URL mode
await htmlToPdf({ url: "https://example.com" }, "page.pdf");
// Data mode
const html = "<h1>Hello PDF</h1><p>Generated from HTML.</p>";
await htmlToPdf({ data: Buffer.from(html).toString("base64") }, "page.pdf");
// With options
await htmlToPdf({
url: "https://example.com",
options: {
landscape: true,
printBackground: true,
marginTop: 0.5,
marginBottom: 0.5,
marginLeft: 0.5,
marginRight: 0.5,
},
}, "page.pdf");
<?php
$BASE_URL = 'https://htmlpdfs.com';
$TOKEN = 'YOUR_TOKEN';
function htmlToPdf(string $baseUrl, string $token, array $payload, string $outFile): void {
$ch = curl_init("$baseUrl/pdf");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Authorization: Bearer $token",
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$pdf = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($code !== 200) throw new \RuntimeException("HTTP $code: $pdf");
file_put_contents($outFile, $pdf);
}
// URL mode
htmlToPdf($BASE_URL, $TOKEN, ['url' => 'https://example.com'], 'page.pdf');
// Data mode
$html = '<h1>Hello PDF</h1><p>Generated from HTML.</p>';
$encoded = base64_encode($html);
htmlToPdf($BASE_URL, $TOKEN, ['data' => $encoded], 'page.pdf');
// With options
htmlToPdf($BASE_URL, $TOKEN, [
'url' => 'https://example.com',
'options' => [
'landscape' => true,
'printBackground'=> true,
'marginTop' => 0.5,
'marginBottom' => 0.5,
'marginLeft' => 0.5,
'marginRight' => 0.5,
],
], 'page.pdf');
200 OK; write it directly to a .pdf file.data field must be standard base64 (not URL-safe) with no line breaks.paperWidth: 8.5, paperHeight: 11. A4 is the default (8.27 × 11.69).preferCSSPageSize: true to let the HTML control the page size via the CSS @page rule.