For AI agents: a documentation index is available at /llms.txt
Skip to main content

Generate a PDF

Export any webpage or HTML content as a PDF using the Browserless PDF API.

Prerequisites

Steps

Use the /pdf REST endpoint to generate a PDF from a URL. No WebSocket connection needed.

View Full Code on GitHub

1. Build the request

Append your token to the PDF endpoint:

https://production-sfo.browserless.io/pdf?token=YOUR_API_TOKEN_HERE

2. Send the request

curl -X POST \
"https://production-sfo.browserless.io/pdf?token=YOUR_API_TOKEN_HERE" \
-H 'Cache-Control: no-cache' \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"options": {
"displayHeaderFooter": true,
"printBackground": true,
"format": "A4"
}
}' \
-o output.pdf

3. Check the output

The response is a raw PDF binary written to output.pdf in the current directory.

Next steps