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

# PDF

> Render the active page as a PDF and return the binary bytes.

## Overview

Renders the session's active page as a PDF via Chrome's `Page.printToPDF` and returns the binary PDF in the response body. Response `Content-Type` is `application/pdf`.

## Path Parameters

<ParamField path="id" type="string" required={true}>
  Browser session ID (UUID).
</ParamField>

## Body

<ParamField body="url" type="string">
  Optional URL to navigate to before rendering. If omitted, the current page is printed.
</ParamField>

<ParamField body="format" type="string">
  Paper format. One of `Letter`, `Legal`, `Tabloid`, `Ledger`, `A0`, `A1`, `A2`, `A3`, `A4`, `A5`, `A6`. When set, overrides `paperWidth` / `paperHeight`.
</ParamField>

<ParamField body="landscape" type="boolean" default="false">
  Paper orientation.
</ParamField>

<ParamField body="printBackground" type="boolean" default="false">
  Include background colors and images.
</ParamField>

<ParamField body="scale" type="number" default="1">
  Render scale. `1` = 100%.
</ParamField>

<ParamField body="paperWidth" type="number" default="8.5">
  Paper width in inches. Ignored when `format` is set.
</ParamField>

<ParamField body="paperHeight" type="number" default="11">
  Paper height in inches. Ignored when `format` is set.
</ParamField>

<ParamField body="margin" type="object">
  Page margins in inches.

  <Expandable title="margin fields">
    <ParamField body="top" type="number" />

    <ParamField body="bottom" type="number" />

    <ParamField body="left" type="number" />

    <ParamField body="right" type="number" />
  </Expandable>
</ParamField>

<ParamField body="pageRanges" type="string">
  One-based page ranges, e.g. `1-5, 8, 11-13`.
</ParamField>

<ParamField body="displayHeaderFooter" type="boolean" default="false">
  Display the header and footer templates.
</ParamField>

<ParamField body="headerTemplate" type="string">
  HTML template for the header. Supports CSS classes `date`, `title`, `url`, `pageNumber`, `totalPages`.
</ParamField>

<ParamField body="footerTemplate" type="string">
  HTML template for the footer. Same substitutions as `headerTemplate`.
</ParamField>

<ParamField body="preferCSSPageSize" type="boolean" default="false">
  When true, prefer page size defined by `@page` CSS rules.
</ParamField>

## Example Request

<CodeGroup>
  ```bash cURL (current page, default) theme={null}
  curl -X POST "https://api.scrapengine.io/api/v1/browser/sessions/baa3f390-fa6e-4a24-b84a-a575a5f3a9c7/pdf" \
    -H "Authorization: Bearer $SCRAPENGINE_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{}' \
    -o output.pdf
  ```

  ```bash cURL (navigate + A4 landscape) theme={null}
  curl -X POST "https://api.scrapengine.io/api/v1/browser/sessions/baa3f390-fa6e-4a24-b84a-a575a5f3a9c7/pdf" \
    -H "Authorization: Bearer $SCRAPENGINE_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "url": "https://example.com",
      "format": "A4",
      "landscape": true,
      "printBackground": true
    }' \
    -o output.pdf
  ```
</CodeGroup>

## Response

### Success Response (200)

Binary PDF. Response headers:

* `Content-Type: application/pdf`

Pipe to a file with `-o output.pdf` in cURL, or read `response.body` as bytes.

### Error Responses

| Status | Description                                                         |
| ------ | ------------------------------------------------------------------- |
| `400`  | Invalid body — unknown `format`, bad margin, or scale out of range. |
| `401`  | Unauthorized — invalid or missing API key.                          |
| `404`  | Session not found or not owned by the caller.                       |
| `503`  | The browser session is temporarily unreachable.                     |
