HTML to PDF Service
| Method | Path | Description |
| GET | / | This page |
| POST | /pdf | Convert HTML to PDF (JSON body with url or base64 HTML) |
| GET | /serve/:filename | Serve a static file from the PDF folder |
| GET | /dashboard | User dashboard |
| POST | /organizations | Create an organization |
| POST | /auth/register | Register a new user account |
| POST | /auth/login | Log in and receive a JWT |
| POST | /auth/logout | Log out |
| GET | /auth/me | Current user info |
| POST | /auth/change-password | Change password |
| POST | /auth/forgot-password | Request a password reset email |
| POST | /auth/reset-password | Reset password with token |
| GET | /auth/verify-email | Verify email address |
| POST | /auth/resend-verification | Resend verification email |
Pricing
| Plan | Requests / month | Monthly | Yearly |
| Starter | 50,000 | $9.99 | $99.99 |
| Pro | 250,000 | $39.99 | $399.99 |
| Business | 1,000,000 | $99.99 | $999.99 |
Get started →
POST /pdf — Usage Examples
The /pdf endpoint accepts a JSON body and returns raw PDF bytes (application/pdf).
All requests must include an Authorization: Bearer <token> header.
Request variants
- URL mode — pass a
url field; Chrome fetches and renders the page.
- Data mode — pass a
data field containing the HTML, base64-encoded.
- Both modes accept an optional
options object (see Print options below).
Print options (all optional)
| 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 |
curl
# 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
Python
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)
JavaScript (Node.js)
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
<?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');
Notes for LLM consumers
- The response body is raw PDF bytes when the status is
200 OK; write it directly to a .pdf file.
- On error the service returns a non-200 status with a plain-text body describing the problem.
- The
data field must be standard base64 (not URL-safe) with no line breaks.
- Paper sizes: US Letter is
paperWidth: 8.5, paperHeight: 11. A4 is the default (8.27 × 11.69).
- Set
preferCSSPageSize: true to let the HTML control the page size via the CSS @page rule.