> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pocketutils.com/llms.txt
> Use this file to discover all available pages before exploring further.

# URL to PDF

> Convert a live URL into a print-ready PDF document.

Renders a URL with headless Chromium and prints it to a paginated PDF: navigates, waits for the network to settle, scrolls to trigger lazy-loaded content, waits for images and fonts to finish, then prints. The finished file is written to temporary storage and its filename returned.

<Info>
  **2 credits** per call · Typical response time \~340ms
</Info>

## Body parameters

<ParamField body="url" type="string" required>
  The page to convert. `https://` is assumed if the scheme is omitted.
</ParamField>

<ParamField body="deviceType" default="desktop" type="string">
  Layout viewport before printing: `desktop` or `mobile`.
</ParamField>

<ParamField body="pageFormat" default="a4" type="string">
  Paper size: `letter`, `legal`, `a0`, `a1`, `a2`, `a3`, `a4`, `a5`, or `a6`.
</ParamField>

<ParamField body="orientation" default="portrait" type="string">
  `portrait` or `landscape`.
</ParamField>

<ParamField body="theme" default="light" type="string">
  Emulated `prefers-color-scheme` while rendering: `light` or `dark`.
</ParamField>

## Response

<ResponseField name="success" type="boolean" required />

<ResponseField name="filename" type="string" required>
  Name of the generated PDF. Download it from `/api/uploads/<filename>` on the same host — the file is temporary and removed after roughly 5 minutes.
</ResponseField>

<ResponseField name="sizeBytes" type="integer" required>
  Size of the generated PDF.
</ResponseField>

<ResponseField name="durationMs" type="integer" required>
  Total server-side time for the conversion.
</ResponseField>

### Response headers

In addition to the [standard headers](/rate-limits-and-credits#response-headers), this endpoint sends:

<ResponseField name="X-Pdf-Cache" type="string">
  `HIT` if served from the short-lived result cache without re-rendering, otherwise `MISS`.
</ResponseField>

<ResponseField name="Server-Timing" type="string">
  Per-stage breakdown (`queue`, `page`, `nav`, `net`, `scroll`, `settle`, `render`, `total`, all in ms).
</ResponseField>

## Errors

| Status | Cause                                                                                                 |
| ------ | ----------------------------------------------------------------------------------------------------- |
| `400`  | `url` missing, or `deviceType` / `pageFormat` / `orientation` / `theme` not one of the allowed values |
| `400`  | The domain could not be resolved, or the target blocked the request (e.g. a private/internal address) |
| `408`  | The page took too long to render                                                                      |

See the full [error reference](/errors) for the platform-level codes (`401`, `402`, `429`) that apply to every endpoint.

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.pocketutils.com/v1/url-to-pdf \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "url": "https://example.com",
      "pageFormat": "a4",
      "orientation": "portrait",
      "theme": "light"
    }'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch("https://api.pocketutils.com/v1/url-to-pdf", {
    method: "POST",
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      url: "https://example.com",
      pageFormat: "a4",
      orientation: "portrait",
    }),
  });
  const { filename } = await res.json();
  const pdfUrl = `https://api.pocketutils.com/api/uploads/${filename}`;
  ```

  ```python Python theme={null}
  import requests

  res = requests.post(
      "https://api.pocketutils.com/v1/url-to-pdf",
      headers={"Authorization": "Bearer YOUR_API_KEY"},
      json={"url": "https://example.com", "pageFormat": "a4", "orientation": "portrait"},
  )
  filename = res.json()["filename"]
  pdf_url = f"https://api.pocketutils.com/api/uploads/{filename}"
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "success": true,
    "filename": "example_com_2026-07-21_9f3a2b1c.pdf",
    "sizeBytes": 512044,
    "durationMs": 356
  }
  ```
</ResponseExample>


## Related topics

- [Introduction](/index.md)
- [Errors](/errors.md)
- [Rate Limits & Credits](/rate-limits-and-credits.md)
- [Broken Link Checker](/api-reference/broken-links.md)
- [Link Extractor](/api-reference/link-extract.md)
