Free PDF Generation API for Developers
Need to generate PDFs programmatically? Whether you're creating invoices, exporting reports, converting documentation, or building a print-ready download feature — you need a PDF API that handles the rendering complexity so you don't have to.
Running your own Puppeteer/Chromium instance is a headache: memory leaks, browser crashes, security sandboxing, and slow cold starts. We built a free PDF generation API powered by Chromium that converts HTML, Markdown, URLs, and templates to pixel-perfect PDFs. 5 free credits, no signup required.
Try it right now
Get an API key and generate your first PDF in under 30 seconds. No signup, no credit card.
Get Free API KeyQuick Start: Generate a PDF from Markdown
1. Get a free API key
curl -X POST https://agent-gateway-kappa.vercel.app/v1/agent-pdfgen/api/keys/create
{
"key": "pdf_abc123...",
"credits": 25,
"note": "25 free credits. Top up with USDC on Base.",
"check_balance": "GET /api/keys/balance with Authorization: Bearer YOUR_KEY"
}
2. Convert Markdown to PDF
curl -X POST https://agent-gateway-kappa.vercel.app/v1/agent-pdfgen/api/pdf/from-markdown \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"markdown": "# Quarterly Report\n\n## Summary\n\nRevenue grew **23%** quarter over quarter.\n\n| Metric | Q4 | Q1 |\n|--------|-----|-----|\n| Revenue | $45K | $55K |\n| Users | 1,200 | 1,800 |\n| Churn | 3.2% | 2.8% |\n\n## Highlights\n\n- Launched 3 new features\n- Expanded to 2 new markets\n- Reduced infrastructure costs by 15%", "theme": "github"}' \
-o report.pdf
This creates a clean, professionally styled PDF using the GitHub theme. The file is ready to share, print, or archive.
4 Ways to Generate PDFs
HTML to PDF
Send raw HTML with CSS styling. Full Chromium rendering — flexbox, grid, web fonts, SVGs all work perfectly.
Markdown to PDF
Send Markdown text and choose a theme (github, dark, minimal). No pre-processing needed — the API handles conversion.
URL to PDF
Provide any URL and get a PDF of the rendered page. Great for archiving web pages, converting docs, or saving receipts.
Template to PDF
Use built-in templates (invoice, report, receipt) with your data. Just pass JSON — the API generates a styled document.
API Reference
| Endpoint | Method | Description |
|---|---|---|
/api/pdf/from-html | POST | Convert HTML string to PDF |
/api/pdf/from-markdown | POST | Convert Markdown to PDF (with theme selection) |
/api/pdf/from-url | POST | Convert any URL to PDF |
/api/pdf/from-template | POST | Generate PDF from built-in template + data |
/api/templates | GET | List available templates (invoice, report, receipt) |
/api/themes | GET | List available Markdown themes (github, dark, minimal) |
PDF Options (all endpoints)
| Parameter | Type | Default | Description |
|---|---|---|---|
format | string | A4 | Page size: A4, Letter, Legal, A3, Tabloid |
landscape | boolean | false | Landscape orientation |
scale | number | 1 | Scale factor (0.1 to 2) |
printBackground | boolean | true | Include background colors and images |
margin | object | 20px all | Page margins: {top, right, bottom, left} |
displayHeaderFooter | boolean | false | Show header and footer |
headerTemplate | string | — | Custom header HTML template |
footerTemplate | string | — | Custom footer HTML template |
pageRanges | string | — | Page ranges to print (e.g., "1-3, 5") |
Code Examples
# HTML to PDF with custom styling
curl -X POST https://agent-gateway-kappa.vercel.app/v1/agent-pdfgen/api/pdf/from-html \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"html": "<h1 style=\"color:#333\">Sales Report</h1><p>Generated on March 3, 2026</p><table style=\"width:100%;border-collapse:collapse\"><tr style=\"background:#f5f5f5\"><th style=\"padding:8px;text-align:left\">Product</th><th>Revenue</th></tr><tr><td style=\"padding:8px\">API Credits</td><td>$12,500</td></tr></table>"}' \
-o report.pdf
# Markdown to PDF (dark theme, landscape)
curl -X POST https://agent-gateway-kappa.vercel.app/v1/agent-pdfgen/api/pdf/from-markdown \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"markdown": "# API Documentation\n\n## Authentication\n\nAll requests require a Bearer token.\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_KEY\" https://api.example.com\n```", "theme": "dark", "landscape": true}' \
-o docs.pdf
# URL to PDF (save any web page)
curl -X POST https://agent-gateway-kappa.vercel.app/v1/agent-pdfgen/api/pdf/from-url \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com", "format": "Letter"}' \
-o page.pdf
# Generate invoice from template
curl -X POST https://agent-gateway-kappa.vercel.app/v1/agent-pdfgen/api/pdf/from-template \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"template": "invoice", "data": {"company": "Acme Corp", "invoice_number": "INV-2026-001", "items": [{"name": "API Credits (1000)", "quantity": 1, "price": 10}, {"name": "Premium Support", "quantity": 1, "price": 49}], "total": 59}}' \
-o invoice.pdf
import requests
API = "https://agent-gateway-kappa.vercel.app/v1/agent-pdfgen"
# Step 1: Get free API key
key_resp = requests.post(f"{API}/api/keys/create")
api_key = key_resp.json()["key"]
print(f"API Key: {api_key}")
headers = {"Authorization": f"Bearer {api_key}"}
# Generate PDF from Markdown
resp = requests.post(
f"{API}/api/pdf/from-markdown",
headers=headers,
json={
"markdown": """# Monthly Report
## Key Metrics
| Metric | Value |
|--------|-------|
| Revenue | $55,000 |
| New Users | 620 |
| Churn Rate | 2.8% |
## Summary
Strong growth across all channels.
""",
"theme": "github",
"format": "A4"
}
)
with open("report.pdf", "wb") as f:
f.write(resp.content)
print(f"PDF saved: {len(resp.content)} bytes")
# Generate invoice from template
invoice = requests.post(
f"{API}/api/pdf/from-template",
headers=headers,
json={
"template": "invoice",
"data": {
"company": "My SaaS Inc",
"invoice_number": "INV-001",
"items": [
{"name": "Pro Plan (Annual)", "quantity": 1, "price": 199},
{"name": "Extra Seats (5)", "quantity": 5, "price": 10}
],
"total": 249
}
}
)
with open("invoice.pdf", "wb") as f:
f.write(invoice.content)
print(f"Invoice saved: {len(invoice.content)} bytes")
const fs = require('fs');
const API = 'https://agent-gateway-kappa.vercel.app/v1/agent-pdfgen';
async function generatePDFs() {
// Step 1: Get free API key
const keyResp = await fetch(`${API}/api/keys/create`, { method: 'POST' });
const { key } = await keyResp.json();
console.log(`API Key: ${key}`);
const headers = {
'Authorization': `Bearer ${key}`,
'Content-Type': 'application/json'
};
// Generate PDF from HTML
const resp = await fetch(`${API}/api/pdf/from-html`, {
method: 'POST',
headers,
body: JSON.stringify({
html: `
<div style="font-family: system-ui; padding: 40px;">
<h1 style="color: #1a1a1a;">Project Status</h1>
<p>Generated: ${new Date().toLocaleDateString()}</p>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px;">
<div style="background: #f0fdf4; padding: 20px; border-radius: 8px;">
<h3>Completed</h3><p style="font-size: 32px; font-weight: bold;">47</p>
</div>
<div style="background: #fef3c7; padding: 20px; border-radius: 8px;">
<h3>In Progress</h3><p style="font-size: 32px; font-weight: bold;">12</p>
</div>
</div>
</div>`
})
});
const buffer = Buffer.from(await resp.arrayBuffer());
fs.writeFileSync('status.pdf', buffer);
console.log(`PDF saved: ${buffer.length} bytes`);
}
generatePDFs();
Built-in Templates
Skip the HTML/CSS work entirely. Send your data as JSON and the API generates professionally styled documents.
Invoice Template
Professional invoice with company name, line items, quantities, prices, and total. Ready for billing systems, SaaS subscriptions, and e-commerce.
# Generate an invoice
curl -X POST https://agent-gateway-kappa.vercel.app/v1/agent-pdfgen/api/pdf/from-template \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"template": "invoice",
"data": {
"company": "Acme Corp",
"invoice_number": "INV-2026-042",
"items": [
{"name": "Pro Plan (Monthly)", "quantity": 1, "price": 49},
{"name": "API Calls (10K)", "quantity": 10, "price": 5},
{"name": "Priority Support", "quantity": 1, "price": 29}
],
"total": 128
}
}' -o invoice.pdf
Report Template
Structured report with sections, summary, and data tables. Perfect for automated weekly/monthly reports, dashboards, and status updates.
Receipt Template
Compact receipt format with item list and total. Ideal for point-of-sale systems, digital receipts, and transaction confirmations.
Use Cases
Automated Invoice Generation
Generate invoices on the fly when customers make purchases. Send the invoice data via API, get a PDF back, and email it to the customer. Works with any billing system — Stripe webhooks, custom payment flows, or manual triggers.
Report Export & Data Visualization
Let users export dashboards, analytics, and data tables as PDFs. Convert your HTML charts and tables to print-ready documents that stakeholders can share, archive, or present.
Documentation & Knowledge Base
Convert your Markdown documentation to styled PDFs. Use the from-markdown endpoint with the GitHub theme for clean, readable docs. Build an offline documentation package by converting all your pages programmatically.
AI Agent Document Generation
Give your AI agent the ability to create professional documents. When your agent writes a report, drafts a proposal, or summarizes research — it can generate a PDF automatically instead of just returning plain text.
# AI agent generates a research summary PDF
curl -X POST https://agent-gateway-kappa.vercel.app/v1/agent-pdfgen/api/pdf/from-markdown \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"markdown": "# Research Summary: Market Analysis\n\n**Generated by AI Agent** | March 2026\n\n## Key Findings\n\n1. Market grew 34% YoY\n2. Top 3 competitors launched new features\n3. Customer sentiment improved to 87% positive\n\n## Recommendation\n\nExpand into the enterprise segment.", "theme": "minimal"}' \
-o summary.pdf
Markdown Themes
| Theme | Background | Font | Best For |
|---|---|---|---|
github | White (#ffffff) | System UI | Documentation, reports, professional docs |
dark | Dark (#0d1117) | System UI | Technical docs, code-heavy content, presentations |
minimal | Off-white (#fafaf9) | Georgia (serif) | Articles, essays, long-form content |
Comparison: PDF Generation APIs in 2026
| Feature | Agent PDF Gen | wkhtmltopdf | PDFShift | DocRaptor | html-pdf-node |
|---|---|---|---|---|---|
| Type | Hosted API | Self-hosted | Hosted API | Hosted API | Self-hosted |
| Free tier | 25 PDFs | Unlimited* | 50/month | 5/month | Unlimited* |
| Signup required | No | N/A | Yes | Yes | N/A |
| Rendering engine | Chromium | WebKit (old) | Chrome | PrinceXML | Puppeteer |
| Modern CSS | Full (flexbox, grid) | Limited | Full | Full | Full |
| Markdown input | Yes (3 themes) | No | No | No | No |
| Templates | Invoice, report, receipt | No | No | No | No |
| URL to PDF | Yes | Yes | Yes | Yes | Yes |
| Paid plans from | $0.002/PDF | Free (self-hosted) | $9/mo | $15/mo | Free (self-hosted) |
* Self-hosted solutions require you to manage Chromium/WebKit instances, handle memory leaks, and deal with browser crashes. Agent PDF Gen handles all infrastructure — just send a request and get a PDF back.
Start generating PDFs now
25 free PDFs. No signup, no credit card, no infrastructure to manage.
Get Free API KeyFrequently Asked Questions
How many free PDFs do I get?
25 PDFs with each API key. No signup or credit card required. Paid credits cost $0.002 per PDF (500 credits per USDC).
What rendering engine is used?
Chromium (via Playwright). This means full support for modern CSS (flexbox, grid, variables), JavaScript execution, web fonts, SVGs, and CSS print media queries. The same engine that powers Chrome DevTools "Print to PDF".
Can I use custom fonts?
Yes. Include web font links (Google Fonts, etc.) in your HTML, or use CSS @font-face with hosted font files. The Chromium engine will load and render them.
What page sizes are supported?
Standard sizes: A4, Letter, Legal, A3, Tabloid. You can also specify custom dimensions using the width and height parameters in any CSS unit (px, in, cm, mm).
Can I add headers and footers?
Yes. Set displayHeaderFooter: true and provide headerTemplate and footerTemplate as HTML strings. Use classes like .pageNumber, .totalPages, .date, and .title for dynamic content.
Is there a size limit?
HTML input is limited to 5MB. URLs are given 30 seconds to load. Most documents generate in under 2 seconds. Generated PDFs are returned directly in the response body.
Can I use this for batch PDF generation?
Yes. Make multiple API calls to generate PDFs in sequence or parallel. With 120 requests per minute on the paid tier, you can generate hundreds of PDFs per hour for batch invoicing, report generation, or document conversion.
More Developer Tools
- Free URL Shortener API — shorten URLs with custom slugs and analytics
- Free Screenshot API — capture website screenshots programmatically
- Free Code Execution API — run Python, JavaScript, Bash online
- Free Web Scraping API — extract content from any URL
- Free AI Agent APIs — 39+ services for autonomous agents
- Explore all 39+ APIs in the Clawdia catalog