Skip to main content
POST
/
browser
/
sessions
/
{id}
/
pdf
PDF
curl --request POST \
  --url https://api.example.com/browser/sessions/{id}/pdf \
  --header 'Content-Type: application/json' \
  --data '
{
  "url": "<string>",
  "format": "<string>",
  "landscape": true,
  "printBackground": true,
  "scale": 123,
  "paperWidth": 123,
  "paperHeight": 123,
  "margin": {
    "top": 123,
    "bottom": 123,
    "left": 123,
    "right": 123
  },
  "pageRanges": "<string>",
  "displayHeaderFooter": true,
  "headerTemplate": "<string>",
  "footerTemplate": "<string>",
  "preferCSSPageSize": true
}
'

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

id
string
required
Browser session ID (UUID).

Body

url
string
Optional URL to navigate to before rendering. If omitted, the current page is printed.
format
string
Paper format. One of Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6. When set, overrides paperWidth / paperHeight.
landscape
boolean
default:"false"
Paper orientation.
printBackground
boolean
default:"false"
Include background colors and images.
scale
number
default:"1"
Render scale. 1 = 100%.
paperWidth
number
default:"8.5"
Paper width in inches. Ignored when format is set.
paperHeight
number
default:"11"
Paper height in inches. Ignored when format is set.
margin
object
Page margins in inches.
pageRanges
string
One-based page ranges, e.g. 1-5, 8, 11-13.
Display the header and footer templates.
headerTemplate
string
HTML template for the header. Supports CSS classes date, title, url, pageNumber, totalPages.
HTML template for the footer. Same substitutions as headerTemplate.
preferCSSPageSize
boolean
default:"false"
When true, prefer page size defined by @page CSS rules.

Example Request

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

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

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