Generate PDF
Generate a PDF document from any web page.
Endpoint
POST /v1/pdf/generate
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | Yes | The URL to convert to PDF |
format | string | No | Paper format: a4, letter, legal (default: a4) |
orientation | string | No | portrait or landscape (default: portrait) |
margin | object | No | Page margins in pixels or with units |
scale | number | No | Scale factor 0.1 to 2 (default: 1) |
print_background | boolean | No | Include background graphics (default: true) |
wait_for | string | No | CSS selector to wait for before generating |
timeout | integer | No | Timeout in milliseconds (default: 30000) |
Margin Object
{
"margin": {
"top": "20px",
"right": "20px",
"bottom": "20px",
"left": "20px"
}
}
Example Request
Basic PDF
curl -X POST https://api.scrapebit.com/v1/pdf/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/article"
}'
Custom Settings
curl -X POST https://api.scrapebit.com/v1/pdf/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/report",
"format": "letter",
"orientation": "landscape",
"margin": {
"top": "1in",
"right": "0.5in",
"bottom": "1in",
"left": "0.5in"
},
"print_background": true,
"scale": 0.8
}'
Response
{
"success": true,
"data": {
"id": "pdf_abc123",
"url": "https://example.com/article",
"pdf_url": "https://api.scrapebit.com/downloads/pdf_abc123.pdf",
"file_size": 245678,
"pages": 3,
"created_at": "2025-01-31T10:30:00Z",
"expires_at": "2025-02-07T10:30:00Z"
},
"credits_used": 2,
"credits_remaining": 97
}
Download PDF
The pdf_url in the response provides a direct download link. This link is valid for 7 days.
curl -O "https://api.scrapebit.com/downloads/pdf_abc123.pdf"
Advanced Options
Header and Footer
{
"url": "https://example.com",
"header_template": "<div style='font-size:10px;text-align:center;width:100%;'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div>",
"footer_template": "<div style='font-size:10px;text-align:center;width:100%;'>Generated by Scrapebit</div>",
"display_header_footer": true
}
Specific Page Range
{
"url": "https://example.com",
"page_ranges": "1-3, 5"
}
Wait for Dynamic Content
{
"url": "https://example.com/charts",
"wait_for": ".chart-loaded",
"timeout": 60000
}
Error Responses
Page Too Large
{
"success": false,
"error": {
"code": "page_too_large",
"message": "The page content exceeds the maximum allowed size for PDF generation"
}
}
Credits
This endpoint uses 2 credits per PDF generated.
Try It Out
POST
/v1/pdf/generateTest the PDF generation endpoint with your API key
Your API key is stored locally in your browser