HTML to PDF API Comparison 2026: With Code Examples
HTML to PDF conversion is a common requirement in web applications — from invoices and reports to certificates and contracts. The right tool depends on your CSS requirements, operating model, and generation volume.
This guide compares the major options available in 2026, with real code examples, so you can make an informed decision for your project.
Major HTML to PDF Solutions
1. wkhtmltopdf (OSS)
A command-line tool based on the QtWebKit rendering engine. It was widely used for years, but its GitHub repository is now archived and read-only.
Pros:
- Free and open source
- Runs directly from the CLI without managing a separate browser automation service
- Simple CLI interface
Cons:
- Maintenance has stalled (archived)
- The target version's Qt WebKit CSS support must be verified
- The archived codebase is not expected to track new browser features
Code Example (CLI)
# Basic conversion
wkhtmltopdf https://example.com output.pdf
# With options (margins, page size)
wkhtmltopdf \
--encoding utf-8 \
--page-size A4 \
--margin-top 20mm \
--margin-bottom 20mm \
invoice.html invoice.pdf
wkhtmltopdf is not recommended for new projects. If you're migrating from it, see our wkhtmltopdf vs Chromium engine guide for alternatives.
2. Puppeteer / Playwright (OSS)
Node.js libraries that control headless Chrome. PDF generation is one of many browser automation features and uses the CSS and JavaScript capabilities of the Chromium version you run.
Pros:
- Access to Chromium CSS/JS features (CSS Grid, Flexbox, Web Fonts)
- Can also capture screenshots
- Page actions and print options are controllable in code
Cons:
- Chrome installation and version management required
- Memory usage depends on pages and concurrency, so measure it in your environment
- Not purpose-built for PDF generation
- Concurrency handling must be implemented manually
Code Example (Node.js / Puppeteer)
const puppeteer = require('puppeteer');
async function generatePdf() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Set HTML content directly
await page.setContent(`
<html>
<style>
body { font-family: Arial, sans-serif; }
.invoice-header { display: flex; justify-content: space-between; }
</style>
<body>
<div class="invoice-header">
<h1>Invoice</h1>
<p>March 2026</p>
</div>
<table>
<tr><td>Service Fee</td><td>$100.00</td></tr>
</table>
</body>
</html>
`);
await page.pdf({
path: 'invoice.pdf',
format: 'A4',
margin: { top: '20mm', bottom: '20mm', left: '15mm', right: '15mm' },
printBackground: true,
});
await browser.close();
}
generatePdf();
For a deeper look at migrating from Puppeteer, see our Puppeteer to API migration guide.
3. Gotenberg (OSS)
A Docker-based PDF generation API that uses Chromium and LibreOffice internally. It exposes a RESTful API for PDF conversion.
Pros:
- One-command Docker setup
- Language-agnostic REST API
- Chromium print features available through the REST API
- Also supports Word/Excel to PDF conversion
Cons:
- You must provide and manage a container or process runtime
- Self-managed scaling
- Resource-loading and HTTP-status failure behavior must be configured for your workload
- CJK font setup requires additional configuration
Code Example (cURL)
# Convert an HTML file to PDF
curl \
--request POST http://localhost:3000/forms/chromium/convert/html \
--form files=@index.html \
--form marginTop=20mm \
--form marginBottom=20mm \
-o output.pdf
# Convert a URL to PDF
curl \
--request POST http://localhost:3000/forms/chromium/convert/url \
--form url=https://example.com \
--form paperWidth=8.27 \
--form paperHeight=11.7 \
-o output.pdf
4. FUNBREW PDF (SaaS)
A managed REST API for generating PDFs from HTML, URLs, and templates. No infrastructure to manage — just an API key to get started.
Pros:
- No conversion browser or binary to manage in your application
- Dual engine (Fast/Quality) for different use cases, with plan and configuration requirements for Quality
- Built-in template engine, webhooks, and email delivery
- A Noto CJK font check helps verify Japanese output
- Documented plan-based monthly quotas and per-minute rate limits
Cons:
- Plan-based limits on monthly generations and requests per minute
- External service dependency
Code Example (cURL)
response=$(curl --fail --silent --show-error \
-X POST https://pdf.funbrew.cloud/api/pdf/generate-from-html \
-H "Authorization: Bearer $FUNBREW_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"html": "<h1>Invoice</h1><p>Total: $100.00</p>",
"options": {
"engine": "quality",
"page-size": "A4",
"margin-top": 20,
"margin-bottom": 20
}
}')
download_url=$(printf '%s' "$response" | jq -er '.data.download_url')
curl --fail --silent --show-error "$download_url" \
-H "Authorization: Bearer $FUNBREW_API_KEY" \
-o invoice.pdf
Code Example (Node.js)
const fs = require('node:fs');
const apiKey = process.env.FUNBREW_API_KEY;
const response = await fetch('https://pdf.funbrew.cloud/api/pdf/generate-from-html', {
method: 'POST',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
html: '<h1>Invoice</h1><p>Total: $100.00</p>',
options: { engine: 'quality', 'page-size': 'A4' },
}),
});
if (!response.ok) throw new Error(`Generation failed: HTTP ${response.status}`);
const result = await response.json();
const download = await fetch(result.data.download_url, {
headers: { Authorization: `Bearer ${apiKey}` },
});
if (!download.ok) throw new Error(`Download failed: HTTP ${download.status}`);
fs.writeFileSync('invoice.pdf', Buffer.from(await download.arrayBuffer()));
Code Example (Python)
import os
import requests
api_key = os.environ['FUNBREW_API_KEY']
headers = {'Authorization': f'Bearer {api_key}'}
response = requests.post(
'https://pdf.funbrew.cloud/api/pdf/generate-from-html',
headers=headers,
json={
'html': '<h1>Invoice</h1><p>Total: $100.00</p>',
'options': {'engine': 'quality', 'page-size': 'A4'},
},
timeout=30,
)
response.raise_for_status()
download = requests.get(
response.json()['data']['download_url'], headers=headers, timeout=30
)
download.raise_for_status()
with open('invoice.pdf', 'wb') as f:
f.write(download.content)
Code Example (PHP)
<?php
$apiKey = getenv('FUNBREW_API_KEY');
$headers = ['Authorization: Bearer ' . $apiKey];
$ch = curl_init('https://pdf.funbrew.cloud/api/pdf/generate-from-html');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [...$headers, 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'html' => '<h1>Invoice</h1><p>Total: $100.00</p>',
'options' => [
'engine' => 'quality',
'page-size' => 'A4',
'margin-top' => 20,
'margin-bottom' => 20,
],
], JSON_THROW_ON_ERROR),
CURLOPT_TIMEOUT => 30,
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($response === false || $httpCode !== 200) {
throw new RuntimeException("Generation failed: HTTP $httpCode");
}
$result = json_decode($response, true, flags: JSON_THROW_ON_ERROR);
$ch = curl_init($result['data']['download_url']);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_TIMEOUT => 30,
]);
$pdf = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($pdf === false || $httpCode !== 200) {
throw new RuntimeException("Download failed: HTTP $httpCode");
}
file_put_contents('invoice.pdf', $pdf);
echo "PDF generated.\n";
Code Example (Gotenberg + Node.js)
const FormData = require('form-data');
const fs = require('fs');
const axios = require('axios');
async function generateWithGotenberg() {
const form = new FormData();
form.append('files', fs.createReadStream('invoice.html'), 'index.html');
form.append('marginTop', '20mm');
form.append('marginBottom', '20mm');
const response = await axios.post(
'http://localhost:3000/forms/chromium/convert/html',
form,
{ headers: form.getHeaders(), responseType: 'arraybuffer' }
);
fs.writeFileSync('output.pdf', response.data);
}
generateWithGotenberg();
Explore more in the documentation or try it live in the Playground. See the invoice automation guide for a real-world example.
Comparison Table
| Feature | wkhtmltopdf | Puppeteer | Gotenberg | FUNBREW PDF |
|---|---|---|---|---|
| CSS Grid/Flexbox | Verify actual output | Available in Chromium | Available in Chromium | Available with Quality when configured |
| CJK Fonts | Manual setup | Manual install | Manual config | Noto CJK verification command |
| REST API | No | Library | Yes | Yes |
| Template variables | No | Implement in your app | Implement in your app | Yes |
| Webhooks | No | Implement in your app | Implement in your app | Yes |
| Email Delivery | No | Implement in your app | Implement in your app | Yes |
| Infrastructure | Self-hosted | Self-hosted | Self-hosted (for example, containers) | Managed |
| Concurrency & scaling | Self-managed | Self-managed | Self-managed | Subject to plan rate limits |
| Free Tier | OSS | OSS | OSS | 30/month |
| Maintenance | Archived | Published | Published | Published |
Recommendations by Use Case
Side Projects & Prototypes
For low-volume PDF generation, Puppeteer is a quick way to get started. However, consider FUNBREW PDF's free tier (30/month) to avoid infrastructure setup entirely.
Startups & Mid-size Teams
If development speed matters, a managed API like FUNBREW PDF is ideal. Skip Chromium version management and scaling headaches — focus on your core product instead.
Large Scale & High Volume
For tens of thousands of PDFs per month, design and scale your own Gotenberg deployment or check FUNBREW PDF's plan quotas and rate limits. The Business plan includes 10,000 PDFs and 300 requests per minute; beyond that (high volume or a dedicated environment), contact us. For strict security requirements, see our PDF API security guide.
Migration Tips
If you're currently using wkhtmltopdf, our wkhtmltopdf vs Chromium engine guide covers your migration options. For those moving from Puppeteer or Playwright, a managed API eliminates the operational overhead of browser management and scaling.
Conclusion
The landscape in 2026 is clear:
- wkhtmltopdf — archived, not recommended for new projects
- Puppeteer/Playwright — flexible but operationally heavy
- Gotenberg — strong with Docker, but scaling is on you
- FUNBREW PDF — managed conversion engines, with plan-based quotas and rate limits
Start free and see for yourself. Try the Playground to generate PDFs right from your browser.
Related
- wkhtmltopdf vs Chromium: Engine Selection Guide — Deep dive into engine differences
- Puppeteer to PDF API Migration Guide — Step-by-step migration from Puppeteer
- PDF API Quickstart — Get started in Node.js, Python, or PHP
- PDF API Pricing Comparison 2026 — Cost breakdown across services
- PDF Template Engine Guide — Dynamic PDF generation with templates
- PDF API Error Handling Guide — Essential error handling for production
- PDF API Production Checklist — End-to-end production readiness
- Automate Invoice PDF Generation — Practical API automation example
- FUNBREW PDF Documentation — API reference and quickstart
- Playground — Try PDF generation in your browser