API

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": false to 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:

ParameterTypeRequiredDefaultDescription
urlstringYesThe URL of the web page to capture. Must be URL-encoded.
timeoutnumberNo30000Maximum time in milliseconds to wait for the page to load.

POST Parameters

URL Parameters

ParameterTypeRequiredDefaultDescription
urlstringYesThe URL of the web page to capture.
authenticationobjectNoCredentials for HTTP Basic Authentication. See authentication.
cookiesarrayNoCookies to set before navigating to the URL. See cookies.
batcharrayNoArray 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.

ParameterTypeDefaultDescription
autoScrollbooleanfalseScroll the page to the bottom before capturing. Triggers lazy-loaded content.
delaynumber0Wait time in milliseconds after the page loads before generating the PDF.
filenamestringSet the Content-Disposition filename on the response.
generatePreviewobjectGenerate a thumbnail preview image. See HTML to PDF — generatePreview.
heightstringOverride page height with a CSS value (e.g., "11in", "297mm").
widthstringOverride page width with a CSS value (e.g., "8.5in", "210mm").
inlinebooleanfalseDisplay the PDF inline in the browser instead of triggering a download.
landscapebooleanfalseGenerate the PDF in landscape orientation.
preferCSSPageSizebooleanfalseUse the CSS @page size instead of the format parameter.
projectIdstringAssociate this request with a project for dashboard organization.
scalenumber1Page rendering scale (0.1 to 2).
timeoutnumber30000Maximum time in milliseconds to wait for page load.
timeZonestringBrowser timezone (IANA name, e.g., "America/New_York").
viewPortobjectBrowser viewport configuration. See HTML to PDF — viewPort.
waitForSelectorobjectWait for a CSS selector before generating. See HTML to PDF — waitForSelector.
waitUntilstring"networkidle2"Navigation completion strategy: "load", "domcontentloaded", "networkidle0", "networkidle2".

PDF Parameters

ParameterTypeDefaultDescription
pageRangesstringPage ranges to include (e.g., "1-5", "1,3,5-7").
formatstring"letter"Page size: "letter", "legal", "tabloid", "ledger", "a0" through "a6".
marginobjectPage margins with CSS units. See HTML to PDF — margin.
printBackgroundbooleantrueInclude background colors and images in the PDF.
headerTemplateobjectCustom page header. See HTML to PDF — headerTemplate.
footerTemplateobjectCustom 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.

FieldTypeRequiredDescription
usernamestringYesThe username for Basic Auth.
passwordstringYesThe 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:

FieldTypeRequiredDefaultDescription
namestringYesCookie name.
valuestringYesCookie value.
domainstringNoDomain the cookie applies to. Defaults to the URL’s domain.
pathstringNo"/"URL path the cookie applies to.
expiresnumberNoUnix timestamp (seconds) when the cookie expires. Omit for a session cookie.
httpOnlybooleanNofalseMark the cookie as HTTP-only (not accessible via JavaScript).
securebooleanNofalseMark the cookie as secure (only sent over HTTPS).
sameSitestringNo"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, the url parameter 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

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 a delay if content renders after API calls complete.
  • Authenticated pages: Prefer cookies over authentication for modern web apps with session-based auth. Use authentication for 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.isMobile to true and viewPort.width to 375 (or similar) to capture the mobile version of a responsive site.