PDF API Reference
Generate high-quality PDFs from any URL or HTML content. Supports custom page sizes, headers/footers, margins, and print-specific styling.
Endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /v2/pdf | Generate a PDF (sync) |
| POST | /v2/pdf/async | Generate a PDF (async with webhook) |
Request Parameters
Source (Required - one of)
| Parameter | Type | Description |
|---|---|---|
| url | string | URL to convert to PDF. Must be publicly accessible. |
| html | string | Raw HTML content to render as PDF. |
Page Options
| Parameter | Type | Default | Description |
|---|---|---|---|
| format | string | "A4" | Page format: "A4", "Letter", "Legal", "Tabloid" |
| width | string | - | Custom width (e.g., "210mm", "8.5in") |
| height | string | - | Custom height (e.g., "297mm", "11in") |
| landscape | boolean | false | Landscape orientation |
| scale | number | 1 | Scale factor (0.1-2) |
Margin Options
| Parameter | Type | Default | Description |
|---|---|---|---|
| margin.top | string | "20mm" | Top margin |
| margin.right | string | "20mm" | Right margin |
| margin.bottom | string | "20mm" | Bottom margin |
| margin.left | string | "20mm" | Left margin |
Header & Footer
| Parameter | Type | Description |
|---|---|---|
| displayHeaderFooter | boolean | Enable header and footer |
| headerTemplate | string | HTML template for header |
| footerTemplate | string | HTML template for footer |
Header/footer templates support these special classes:
date- Current datetitle- Page titleurl- Page URLpageNumber- Current page numbertotalPages- Total number of pages
Additional Options
| Parameter | Type | Description |
|---|---|---|
| printBackground | boolean | Include background graphics (default: true) |
| preferCSSPageSize | boolean | Respect CSS @page size |
| pageRanges | string | Pages to include (e.g., "1-5, 8, 11-13") |
| tagged | boolean | Generate tagged/accessible PDF |
Examples
Basic PDF
Request
{
"url": "https://example.com/report",
"format": "A4"
} Custom Page Size with Margins
Request
{
"url": "https://example.com/invoice",
"width": "8.5in",
"height": "11in",
"margin": {
"top": "1in",
"right": "0.75in",
"bottom": "1in",
"left": "0.75in"
}
} PDF with Header and Footer
Request
{
"url": "https://example.com/document",
"format": "A4",
"displayHeaderFooter": true,
"headerTemplate": "<div style='font-size: 10px; text-align: center; width: 100%;'>Company Name - Confidential</div>",
"footerTemplate": "<div style='font-size: 10px; text-align: center; width: 100%;'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div>",
"margin": {
"top": "100px",
"bottom": "80px"
}
} Landscape Multi-page Report
Request
{
"url": "https://example.com/analytics",
"format": "A4",
"landscape": true,
"printBackground": true,
"pageRanges": "1-10"
} HTML to PDF (Invoice Template)
Request
{
"html": "<!DOCTYPE html><html><head><style>body { font-family: Arial; } .invoice-header { background: #2563eb; color: white; padding: 20px; } .line-item { border-bottom: 1px solid #eee; padding: 10px 0; }</style></head><body><div class='invoice-header'><h1>Invoice #1234</h1></div><div class='line-item'>Service Fee: $99.00</div><div class='line-item'>Total: $99.00</div></body></html>",
"format": "A4",
"margin": {
"top": "20mm",
"right": "20mm",
"bottom": "20mm",
"left": "20mm"
}
} Response
Success Response
{
"success": true,
"data": {
"id": "pdf_xyz789abc123",
"url": "https://cdn.screencraft.dev/p/xyz789.pdf",
"pages": 5,
"size": 1245678,
"format": "A4",
"created_at": "2025-12-27T10:30:00Z",
"expires_at": "2025-12-28T10:30:00Z"
}
} Print Styles
For best results, use CSS print media queries in your HTML:
print.css
@media print {
/* Hide non-essential elements */
.navigation, .sidebar, .footer {
display: none !important;
}
/* Avoid page breaks inside elements */
.content-block {
page-break-inside: avoid;
}
/* Force page break before sections */
.new-section {
page-break-before: always;
}
/* Ensure backgrounds print */
body {
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
} Best Practices
- Use print stylesheets: Apply
@media printstyles for optimal PDF output - Set appropriate margins: Account for header/footer space when using templates
- Test page breaks: Use
page-break-*CSS properties to control content flow - Optimize images: Use appropriately sized images to reduce PDF file size
- Consider accessibility: Enable
tagged: truefor accessible PDFs