URL to PDF
Generate a PDF from a live web page URL. Supports both simple GET requests and full-featured POST requests with authentication, cookies, and batch processing.
Endpoints
GET /v1/url/pdf
POST /v1/url/pdf
The GET endpoint is a convenience method for simple captures with minimal configuration. The POST endpoint supports the full range of parameters. All requests are processed synchronously — the response body is the raw PDF file.
GET /v2/url/pdf
POST /v2/url/pdf
The GET endpoint is a convenience method for simple captures with minimal configuration. The POST endpoint supports the full range of parameters. Requests default to asynchronous processing (async: true, storage: true). Add "async": false to receive the raw PDF directly. See Sync vs. Async for details.
Quick Start (GET)
The simplest way to capture a web page as a PDF — just pass the URL as a query parameter:
cURL
curl -X GET "https://api.cloudlayer.io/v1/url/pdf?url=https://example.com" \
-H "X-API-Key: your-api-key-here" \
--output example.pdf
JavaScript (fetch)
const url = encodeURIComponent("https://example.com");
const response = await fetch(
`https://api.cloudlayer.io/v1/url/pdf?url=${url}`,
{
headers: {
"X-API-Key": "your-api-key-here",
},
}
);
const pdf = await response.arrayBuffer();
Python (requests)
import requests
response = requests.get(
"https://api.cloudlayer.io/v1/url/pdf",
params={"url": "https://example.com"},
headers={"X-API-Key": "your-api-key-here"},
)
with open("example.pdf", "wb") as f:
f.write(response.content)
cURL
curl -X GET "https://api.cloudlayer.io/v2/url/pdf?url=https://example.com&async=false" \
-H "X-API-Key: your-api-key-here" \
--output example.pdf
JavaScript (fetch)
const url = encodeURIComponent("https://example.com");
const response = await fetch(
`https://api.cloudlayer.io/v2/url/pdf?url=${url}&async=false`,
{
headers: {
"X-API-Key": "your-api-key-here",
},
}
);
const pdf = await response.arrayBuffer();
Python (requests)
import requests
response = requests.get(
"https://api.cloudlayer.io/v2/url/pdf",
params={"url": "https://example.com", "async": "false"},
headers={"X-API-Key": "your-api-key-here"},
)
with open("example.pdf", "wb") as f:
f.write(response.content)
Quick Start (POST)
Use POST for full control over the output:
cURL
curl -X POST "https://api.cloudlayer.io/v1/url/pdf" \
-H "X-API-Key: your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"format": "a4",
"margin": {
"top": "1in",
"bottom": "1in",
"left": "0.75in",
"right": "0.75in"
},
"printBackground": true,
"waitUntil": "networkidle0"
}' \
--output example.pdf
JavaScript (fetch)
const response = await fetch("https://api.cloudlayer.io/v1/url/pdf", {
method: "POST",
headers: {
"X-API-Key": "your-api-key-here",
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://example.com",
format: "a4",
margin: { top: "1in", bottom: "1in", left: "0.75in", right: "0.75in" },
printBackground: true,
waitUntil: "networkidle0",
}),
});
const pdf = await response.arrayBuffer();
Python (requests)
import requests
response = requests.post(
"https://api.cloudlayer.io/v1/url/pdf",
headers={
"X-API-Key": "your-api-key-here",
"Content-Type": "application/json",
},
json={
"url": "https://example.com",
"format": "a4",
"margin": {"top": "1in", "bottom": "1in", "left": "0.75in", "right": "0.75in"},
"printBackground": True,
"waitUntil": "networkidle0",
},
)
with open("example.pdf", "wb") as f:
f.write(response.content)
cURL
curl -X POST "https://api.cloudlayer.io/v2/url/pdf" \
-H "X-API-Key: your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"format": "a4",
"margin": {
"top": "1in",
"bottom": "1in",
"left": "0.75in",
"right": "0.75in"
},
"printBackground": true,
"waitUntil": "networkidle0",
"async": false
}' \
--output example.pdf
JavaScript (fetch)
const response = await fetch("https://api.cloudlayer.io/v2/url/pdf", {
method: "POST",
headers: {
"X-API-Key": "your-api-key-here",
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://example.com",
format: "a4",
margin: { top: "1in", bottom: "1in", left: "0.75in", right: "0.75in" },
printBackground: true,
waitUntil: "networkidle0",
async: false,
}),
});
const pdf = await response.arrayBuffer();
Python (requests)
import requests
response = requests.post(
"https://api.cloudlayer.io/v2/url/pdf",
headers={
"X-API-Key": "your-api-key-here",
"Content-Type": "application/json",
},
json={
"url": "https://example.com",
"format": "a4",
"margin": {"top": "1in", "bottom": "1in", "left": "0.75in", "right": "0.75in"},
"printBackground": True,
"waitUntil": "networkidle0",
"async": False,
},
)
with open("example.pdf", "wb") as f:
f.write(response.content)
Tip: Omit
"async": falseto use the default async mode. The API will return a JSON response with the job ID immediately, and the generated PDF will be stored and accessible via the Assets endpoint.
GET Parameters
The GET endpoint accepts these query parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | Yes | — | The URL of the web page to capture. Must be URL-encoded. |
timeout | number | No | 30000 | Maximum time in milliseconds to wait for the page to load. |
POST Parameters
URL Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | Yes | — | The URL of the web page to capture. |
authentication | object | No | — | Credentials for HTTP Basic Authentication. See authentication. |
cookies | array | No | — | Cookies to set before navigating to the URL. See cookies. |
batch | array | No | — | Array of URLs to combine into a single multi-page PDF. See Batch Processing. |
Base Parameters
These parameters control page loading behavior, viewport configuration, and general output settings.
| Parameter | Type | Default | Description |
|---|---|---|---|
autoScroll | boolean | false | Scroll the page to the bottom before capturing. Triggers lazy-loaded content. |
delay | number | 0 | Wait time in milliseconds after the page loads before generating the PDF. |
filename | string | — | Set the Content-Disposition filename on the response. |
generatePreview | object | — | Generate a thumbnail preview image. See HTML to PDF — generatePreview. |
height | string | — | Override page height with a CSS value (e.g., "11in", "297mm"). |
width | string | — | Override page width with a CSS value (e.g., "8.5in", "210mm"). |
inline | boolean | false | Display the PDF inline in the browser instead of triggering a download. |
landscape | boolean | false | Generate the PDF in landscape orientation. |
preferCSSPageSize | boolean | false | Use the CSS @page size instead of the format parameter. |
projectId | string | — | Associate this request with a project for dashboard organization. |
scale | number | 1 | Page rendering scale (0.1 to 2). |
timeout | number | 30000 | Maximum time in milliseconds to wait for page load. |
timeZone | string | — | Browser timezone (IANA name, e.g., "America/New_York"). |
viewPort | object | — | Browser viewport configuration. See HTML to PDF — viewPort. |
waitForSelector | object | — | Wait for a CSS selector before generating. See HTML to PDF — waitForSelector. |
waitUntil | string | "networkidle2" | Navigation completion strategy: "load", "domcontentloaded", "networkidle0", "networkidle2". |
PDF Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
pageRanges | string | — | Page ranges to include (e.g., "1-5", "1,3,5-7"). |
format | string | "letter" | Page size: "letter", "legal", "tabloid", "ledger", "a0" through "a6". |
margin | object | — | Page margins with CSS units. See HTML to PDF — margin. |
printBackground | boolean | true | Include background colors and images in the PDF. |
headerTemplate | object | — | Custom page header. See HTML to PDF — headerTemplate. |
footerTemplate | object | — | Custom page footer. See HTML to PDF — footerTemplate. |
Parameter Details
authentication Object
Provide HTTP Basic Authentication credentials. The browser will send these credentials when navigating to the URL.
| Field | Type | Required | Description |
|---|---|---|---|
username | string | Yes | The username for Basic Auth. |
password | string | Yes | The password for Basic Auth. |
{
"url": "https://staging.example.com/report",
"authentication": {
"username": "admin",
"password": "s3cur3p@ss"
}
}
cookies Array
Set cookies in the browser before navigating to the URL. Each cookie is an object with the following fields:
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | Yes | — | Cookie name. |
value | string | Yes | — | Cookie value. |
domain | string | No | — | Domain the cookie applies to. Defaults to the URL’s domain. |
path | string | No | "/" | URL path the cookie applies to. |
expires | number | No | — | Unix timestamp (seconds) when the cookie expires. Omit for a session cookie. |
httpOnly | boolean | No | false | Mark the cookie as HTTP-only (not accessible via JavaScript). |
secure | boolean | No | false | Mark the cookie as secure (only sent over HTTPS). |
sameSite | string | No | "Lax" | SameSite attribute: "Strict", "Lax", or "None". |
{
"url": "https://app.example.com/dashboard",
"cookies": [
{
"name": "session_id",
"value": "abc123def456",
"domain": "app.example.com",
"path": "/",
"secure": true,
"httpOnly": true
},
{
"name": "theme",
"value": "dark",
"domain": "app.example.com"
}
]
}
Use case: Cookies let you capture authenticated pages (dashboards, admin panels, user profiles) by passing the user’s session cookie. This is often simpler than Basic Auth for applications with cookie-based session management.
Batch Processing
Combine multiple URLs into a single multi-page PDF. Each URL is rendered as a separate section in the output document.
Pass an array of URL strings in the batch parameter:
{
"batch": [
"https://example.com/report/page-1",
"https://example.com/report/page-2",
"https://example.com/report/page-3"
],
"format": "a4",
"printBackground": true,
"waitUntil": "networkidle0"
}
Note: When using
batch, theurlparameter is ignored. All other parameters (format, margin, viewport, etc.) apply to every URL in the batch.
Batch Example
cURL
curl -X POST "https://api.cloudlayer.io/v2/url/pdf" \
-H "X-API-Key: your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"batch": [
"https://example.com/chapter-1",
"https://example.com/chapter-2",
"https://example.com/chapter-3"
],
"format": "letter",
"margin": {
"top": "1in",
"bottom": "1in",
"left": "1in",
"right": "1in"
},
"printBackground": true,
"filename": "full-report.pdf"
}' \
--output full-report.pdf
JavaScript (fetch)
const response = await fetch("https://api.cloudlayer.io/v2/url/pdf", {
method: "POST",
headers: {
"X-API-Key": "your-api-key-here",
"Content-Type": "application/json",
},
body: JSON.stringify({
batch: [
"https://example.com/chapter-1",
"https://example.com/chapter-2",
"https://example.com/chapter-3",
],
format: "letter",
margin: { top: "1in", bottom: "1in", left: "1in", right: "1in" },
printBackground: true,
filename: "full-report.pdf",
}),
});
const pdf = await response.arrayBuffer();
Python (requests)
import requests
response = requests.post(
"https://api.cloudlayer.io/v2/url/pdf",
headers={
"X-API-Key": "your-api-key-here",
"Content-Type": "application/json",
},
json={
"batch": [
"https://example.com/chapter-1",
"https://example.com/chapter-2",
"https://example.com/chapter-3",
],
"format": "letter",
"margin": {"top": "1in", "bottom": "1in", "left": "1in", "right": "1in"},
"printBackground": True,
"filename": "full-report.pdf",
},
)
with open("full-report.pdf", "wb") as f:
f.write(response.content)
Authentication Example
Capture a page behind HTTP Basic Auth:
cURL
curl -X POST "https://api.cloudlayer.io/v2/url/pdf" \
-H "X-API-Key: your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"url": "https://staging.internal.example.com/admin/report",
"authentication": {
"username": "report-viewer",
"password": "s3cur3p@ss"
},
"format": "a4",
"printBackground": true,
"waitUntil": "networkidle0",
"timeout": 60000
}' \
--output admin-report.pdf
Cookie Authentication Example
Capture an authenticated dashboard by injecting session cookies:
cURL
curl -X POST "https://api.cloudlayer.io/v2/url/pdf" \
-H "X-API-Key: your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"url": "https://app.example.com/dashboard",
"cookies": [
{
"name": "auth_token",
"value": "eyJhbGciOiJIUzI1NiIs...",
"domain": "app.example.com",
"secure": true,
"httpOnly": true,
"sameSite": "Lax"
}
],
"format": "letter",
"landscape": true,
"printBackground": true,
"waitUntil": "networkidle0",
"delay": 2000
}' \
--output dashboard.pdf
Tips
- Dynamic content: Use
waitUntil: "networkidle0"for SPAs and pages that fetch data via AJAX. Add adelayif content renders after API calls complete. - Authenticated pages: Prefer
cookiesoverauthenticationfor modern web apps with session-based auth. Useauthenticationfor sites with HTTP Basic Auth (common in staging environments). - Batch limits: Batch processing is subject to your plan’s timeout limits. For large batches, consider using async mode.
- CORS and firewalls: The URL must be publicly accessible from cloudlayer.io servers. For internal/private URLs, consider using the HTML to PDF endpoint instead.
- Mobile rendering: Set
viewPort.isMobiletotrueandviewPort.widthto375(or similar) to capture the mobile version of a responsive site.