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": "letter", "landscape": false, "scale": 1.0, "print_background": true, "margin": "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 (a0-a6, letter, legal, tabloid) |
width |
string | — | Custom width (CSS units: "8.5in", "210mm") |
height |
string | — | Custom height (overrides paper) |
landscape |
boolean | false |
Landscape orientation |
scale |
number | 1.0 |
Render scale (0.1 to 2.0) |
fit_one_page |
boolean | false |
Scale content to fit one page |
margin |
string | 0 |
Uniform margin (CSS units) |
margin_top |
string | — | Top margin (overrides uniform) |
margin_right |
string | — | Right margin |
margin_bottom |
string | — | Bottom margin |
margin_left |
string | — | Left margin |
print_background |
boolean | true |
Include background graphics |
prefer_css_page_size |
boolean | false |
Use CSS @page declarations |
page_ranges |
string | — | Pages to include (e.g., "1-5, 8") |
header |
string | — | HTML template for header |
footer |
string | — | HTML template for footer |
Paper Sizes
| Size | Dimensions |
|---|---|
letter |
8.5 × 11 in (216 × 279 mm) |
legal |
8.5 × 14 in (216 × 356 mm) |
tabloid |
11 × 17 in (279 × 432 mm) |
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 |
{ "pdf": { "paper": "a4" } }
Custom Dimensions
Override paper size with custom dimensions:
{ "pdf": { "width": "8.5in", "height": "14in" } }
Orientation
Portrait (Default)
{ "pdf": { "landscape": false } }
Landscape
{ "pdf": { "landscape": true } }
Scale
Adjust the rendering scale (0.1 to 2.0):
{ "pdf": { "scale": 0.8 } }
Useful for fitting content that's slightly too wide for the page.
Margins
Set margins using CSS units (cm, mm, in, px):
Uniform Margin
{ "pdf": { "margin": "1cm" } }
Individual Margins
{ "pdf": { "margin_top": "2cm", "margin_right": "1.5cm", "margin_bottom": "2cm", "margin_left": "1.5cm" } }
No Margins
{ "pdf": { "margin": "0" } }
Background Graphics
Include background colors and images (enabled by default):
{ "pdf": { "print_background": true } }
Set to false for text-only output.
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.
Page Ranges
Print specific pages:
{ "pdf": { "page_ranges": "1-5, 8, 10-12" } }
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>
Note: When using headers or footers, ensure you have sufficient margins to accommodate them.
Using the PDF Preset
For common PDF use cases, use the preset:
{ "url": "https://example.com/report", "preset": "pdf_document" }
This sets letter paper with print backgrounds enabled and 1cm margins.
GET Request Parameters
For GET requests, use flat parameters with pdf_ prefix:
GET /v1/screenshot?url=https://example.com&format=pdf&pdf_paper=a4&pdf_landscape=true&pdf_print_background=true
| Query Parameter | Maps To |
|---|---|
pdf_paper |
pdf.paper |
pdf_width |
pdf.width |
pdf_height |
pdf.height |
pdf_landscape |
pdf.landscape |
pdf_scale |
pdf.scale |
pdf_fit_one_page |
pdf.fit_one_page |
pdf_margin |
pdf.margin |
pdf_margin_top |
pdf.margin_top |
pdf_margin_right |
pdf.margin_right |
pdf_margin_bottom |
pdf.margin_bottom |
pdf_margin_left |
pdf.margin_left |
pdf_print_background |
pdf.print_background |
pdf_prefer_css_page_size |
pdf.prefer_css_page_size |
pdf_page_ranges |
pdf.page_ranges |
pdf_header |
pdf.header |
pdf_footer |
pdf.footer |
Common Patterns
Print-Ready Report
{ "url": "https://example.com/report", "output": { "format": "pdf" }, "pdf": { "paper": "a4", "print_background": true, "margin": "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", "print_background": true, "margin_top": "1in", "margin_right": "0.75in", "margin_bottom": "1in", "margin_left": "0.75in" } }
Wide Report (Landscape)
{ "url": "https://example.com/dashboard", "output": { "format": "pdf" }, "pdf": { "paper": "a4", "landscape": true, "print_background": true } }
One-Page Summary
{ "url": "https://example.com/summary", "output": { "format": "pdf" }, "pdf": { "paper": "letter", "fit_one_page": true, "print_background": true } }
Examples
Generate Report PDF
curl
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", "print_background": true, "margin": "2cm", "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
Java
import com.renderscreenshot.sdk.Client; import com.renderscreenshot.sdk.TakeOptions; import java.nio.file.Files; import java.nio.file.Path; Client client = new Client("rs_live_xxxxx"); byte[] pdf = client.take( TakeOptions.url("https://example.com/quarterly-report") .format("pdf") .pdfPaperSize("a4") .pdfPrintBackground() .pdfMargin("2cm") .pdfHeader("<div style=\"font-size: 9px; text-align: right; padding-right: 1cm;\">Q4 2024 Report</div>") .pdfFooter("<div style=\"font-size: 9px; text-align: center;\">Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div>") ); Files.write(Path.of("report.pdf"), pdf);
Node.js
import { Client, TakeOptions } from 'renderscreenshot'; const client = new Client('rs_live_xxxxx'); const pdf = await client.take( TakeOptions.url('https://example.com/quarterly-report') .format('pdf') .pdfPaperSize('a4') .pdfPrintBackground() .pdfMargin('2cm') .pdfHeader('<div style="font-size: 9px; text-align: right; padding-right: 1cm;">Q4 2024 Report</div>') .pdfFooter('<div style="font-size: 9px; text-align: center;">Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>') );
PHP
use RenderScreenshot\Client; use RenderScreenshot\TakeOptions; $client = new Client('rs_live_xxxxx'); $pdf = $client->take( TakeOptions::url('https://example.com/quarterly-report') ->format('pdf') ->pdfPaperSize('a4') ->pdfPrintBackground() ->pdfMargin('2cm') ->pdfHeader('<div style="font-size: 9px; text-align: right; padding-right: 1cm;">Q4 2024 Report</div>') ->pdfFooter('<div style="font-size: 9px; text-align: center;">Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>') ); file_put_contents('report.pdf', $pdf);
Python
from renderscreenshot import Client, TakeOptions client = Client('rs_live_xxxxx') pdf = client.take( TakeOptions.url('https://example.com/quarterly-report') .format('pdf') .pdf_paper_size('a4') .pdf_print_background() .pdf_margin('2cm') .pdf_header('<div style="font-size: 9px; text-align: right; padding-right: 1cm;">Q4 2024 Report</div>') .pdf_footer('<div style="font-size: 9px; text-align: center;">Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>') ) with open('report.pdf', 'wb') as f: f.write(pdf)
Ruby
require 'net/http' require 'json' uri = URI('https://api.renderscreenshot.com/v1/screenshot') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri) request['Authorization'] = 'Bearer rs_live_xxxxx' request['Content-Type'] = 'application/json' request.body = { url: 'https://example.com/quarterly-report', output: { format: 'pdf' }, pdf: { paper: 'a4', print_background: true, margin: '2cm', 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>' } }.to_json response = http.request(request) File.binwrite('report.pdf', response.body)
Generate PDF via GET
curl "https://api.renderscreenshot.com/v1/screenshot?url=https://example.com&format=pdf&pdf_paper=letter&pdf_print_background=true&api_key=rs_live_xxxxx" \ --output screenshot.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" } }
Response
The PDF response includes these headers:
| Header | Description |
|---|---|
Content-Type |
application/pdf |
Content-Disposition |
inline; filename="screenshot.pdf" |
X-Screenshot-Width |
PDF width |
X-Screenshot-Height |
PDF height |
X-Screenshot-Size |
File size in bytes |
X-Screenshot-Format |
pdf |
X-Cache-URL |
CDN URL for the cached PDF |
See Also
- Output Options - Format and quality settings
- Presets Reference - The pdf_document preset
- Browser Options - Print media type