PDF Options
Generate PDF documents with custom paper sizes, margins, headers, footers, and print settings.
Enable PDF Output
Set the output format to PDF:
{ "url": "https://example.com", "output": { "format": "pdf" } }
Full Configuration
{ "output": { "format": "pdf" }, "pdf": { "paper": "a4", "landscape": false, "background": true, "margin": { "top": "1cm", "right": "1cm", "bottom": "1cm", "left": "1cm" }, "fit_one_page": false, "header": "<div style='font-size: 10px;'>Header</div>", "footer": "<div style='font-size: 10px;'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div>" } }
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
paper |
string | letter |
Paper size |
landscape |
boolean | false |
Landscape orientation |
background |
boolean | false |
Print background graphics |
margin |
object | 0 |
Page margins (CSS units) |
fit_one_page |
boolean | false |
Scale content to fit one page |
header |
string | — | HTML header template |
footer |
string | — | HTML footer template |
Paper Sizes
| Size | Dimensions |
|---|---|
a0 |
841 × 1189 mm |
a1 |
594 × 841 mm |
a2 |
420 × 594 mm |
a3 |
297 × 420 mm |
a4 |
210 × 297 mm |
a5 |
148 × 210 mm |
a6 |
105 × 148 mm |
letter |
8.5 × 11 in |
legal |
8.5 × 14 in |
tabloid |
11 × 17 in |
{ "pdf": { "paper": "a4" } }
Orientation
Portrait (Default)
{ "pdf": { "landscape": false } }
Landscape
{ "pdf": { "landscape": true } }
Margins
Set margins using CSS units (cm, mm, in, px):
{ "pdf": { "margin": { "top": "2cm", "right": "1.5cm", "bottom": "2cm", "left": "1.5cm" } } }
No Margins
{ "pdf": { "margin": { "top": "0", "right": "0", "bottom": "0", "left": "0" } } }
Background Graphics
Include background colors and images:
{ "pdf": { "background": true } }
Note: Without background: true, only text and foreground content are printed.
Fit to One Page
Scale content to fit on a single page:
{ "pdf": { "fit_one_page": true } }
Useful for reports or summaries that should be single-page documents.
Headers and Footers
Add HTML templates for headers and footers:
{ "pdf": { "header": "<div style='font-size: 9px; width: 100%; text-align: center;'>Company Report</div>", "footer": "<div style='font-size: 9px; width: 100%; text-align: center;'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div>" } }
Available Template Variables
| Class | Description |
|---|---|
pageNumber |
Current page number |
totalPages |
Total number of pages |
date |
Current date |
title |
Document title |
url |
Page URL |
Header Example
<div style="font-size: 10px; padding: 0 1cm; display: flex; justify-content: space-between;"> <span>Confidential</span> <span class="date"></span> </div>
Footer Example
<div style="font-size: 10px; padding: 0 1cm; display: flex; justify-content: space-between;"> <span class="url"></span> <span>Page <span class="pageNumber"></span>/<span class="totalPages"></span></span> </div>
Using the PDF Preset
For common PDF use cases, use the preset:
{ "url": "https://example.com/report", "preset": "pdf_document" }
This sets A4 paper with print backgrounds enabled.
Common Patterns
Print-Ready Report
{ "url": "https://example.com/report", "output": { "format": "pdf" }, "pdf": { "paper": "a4", "background": true, "margin": { "top": "2cm", "right": "2cm", "bottom": "2cm", "left": "2cm" }, "footer": "<div style='font-size: 9px; text-align: center;'>Page <span class='pageNumber'></span></div>" } }
Invoice PDF
{ "url": "https://app.example.com/invoice/123", "output": { "format": "pdf" }, "pdf": { "paper": "letter", "background": true, "margin": { "top": "1in", "right": "0.75in", "bottom": "1in", "left": "0.75in" } } }
Wide Report (Landscape)
{ "url": "https://example.com/dashboard", "output": { "format": "pdf" }, "pdf": { "paper": "a4", "landscape": true, "background": true } }
Examples
Generate Report PDF
curl -X POST https://api.renderscreenshot.com/v1/screenshot \ -H "Authorization: Bearer rs_live_xxxxx" \ -H "Content-Type: application/json" \ -d '{ "url": "https://example.com/quarterly-report", "output": { "format": "pdf" }, "pdf": { "paper": "a4", "background": true, "margin": { "top": "2cm", "bottom": "2cm", "left": "1.5cm", "right": "1.5cm" }, "header": "<div style=\"font-size: 9px; text-align: right; padding-right: 1cm;\">Q4 2024 Report</div>", "footer": "<div style=\"font-size: 9px; text-align: center;\">Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div>" } }' \ --output report.pdf
Print CSS
For best results, ensure your page has print-specific CSS:
@media print { .no-print { display: none; } .page-break { page-break-after: always; } }
Use the print media type in browser options:
{ "browser": { "media": "print" } }
See Also
- Output Options - Format and quality settings
- Presets Reference - The pdf_document preset
- Browser Options - Print media type