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
}
'import requests
url = "https://api.example.com/browser/sessions/{id}/pdf"
payload = {
"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
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
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
})
};
fetch('https://api.example.com/browser/sessions/{id}/pdf', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/browser/sessions/{id}/pdf",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'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
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/browser/sessions/{id}/pdf"
payload := strings.NewReader("{\n \"url\": \"<string>\",\n \"format\": \"<string>\",\n \"landscape\": true,\n \"printBackground\": true,\n \"scale\": 123,\n \"paperWidth\": 123,\n \"paperHeight\": 123,\n \"margin\": {\n \"top\": 123,\n \"bottom\": 123,\n \"left\": 123,\n \"right\": 123\n },\n \"pageRanges\": \"<string>\",\n \"displayHeaderFooter\": true,\n \"headerTemplate\": \"<string>\",\n \"footerTemplate\": \"<string>\",\n \"preferCSSPageSize\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/browser/sessions/{id}/pdf")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"<string>\",\n \"format\": \"<string>\",\n \"landscape\": true,\n \"printBackground\": true,\n \"scale\": 123,\n \"paperWidth\": 123,\n \"paperHeight\": 123,\n \"margin\": {\n \"top\": 123,\n \"bottom\": 123,\n \"left\": 123,\n \"right\": 123\n },\n \"pageRanges\": \"<string>\",\n \"displayHeaderFooter\": true,\n \"headerTemplate\": \"<string>\",\n \"footerTemplate\": \"<string>\",\n \"preferCSSPageSize\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/browser/sessions/{id}/pdf")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"<string>\",\n \"format\": \"<string>\",\n \"landscape\": true,\n \"printBackground\": true,\n \"scale\": 123,\n \"paperWidth\": 123,\n \"paperHeight\": 123,\n \"margin\": {\n \"top\": 123,\n \"bottom\": 123,\n \"left\": 123,\n \"right\": 123\n },\n \"pageRanges\": \"<string>\",\n \"displayHeaderFooter\": true,\n \"headerTemplate\": \"<string>\",\n \"footerTemplate\": \"<string>\",\n \"preferCSSPageSize\": true\n}"
response = http.request(request)
puts response.read_bodyTools
Render the active page as a PDF and return the binary bytes.
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
}
'import requests
url = "https://api.example.com/browser/sessions/{id}/pdf"
payload = {
"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
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
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
})
};
fetch('https://api.example.com/browser/sessions/{id}/pdf', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/browser/sessions/{id}/pdf",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'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
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/browser/sessions/{id}/pdf"
payload := strings.NewReader("{\n \"url\": \"<string>\",\n \"format\": \"<string>\",\n \"landscape\": true,\n \"printBackground\": true,\n \"scale\": 123,\n \"paperWidth\": 123,\n \"paperHeight\": 123,\n \"margin\": {\n \"top\": 123,\n \"bottom\": 123,\n \"left\": 123,\n \"right\": 123\n },\n \"pageRanges\": \"<string>\",\n \"displayHeaderFooter\": true,\n \"headerTemplate\": \"<string>\",\n \"footerTemplate\": \"<string>\",\n \"preferCSSPageSize\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/browser/sessions/{id}/pdf")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"<string>\",\n \"format\": \"<string>\",\n \"landscape\": true,\n \"printBackground\": true,\n \"scale\": 123,\n \"paperWidth\": 123,\n \"paperHeight\": 123,\n \"margin\": {\n \"top\": 123,\n \"bottom\": 123,\n \"left\": 123,\n \"right\": 123\n },\n \"pageRanges\": \"<string>\",\n \"displayHeaderFooter\": true,\n \"headerTemplate\": \"<string>\",\n \"footerTemplate\": \"<string>\",\n \"preferCSSPageSize\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/browser/sessions/{id}/pdf")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"<string>\",\n \"format\": \"<string>\",\n \"landscape\": true,\n \"printBackground\": true,\n \"scale\": 123,\n \"paperWidth\": 123,\n \"paperHeight\": 123,\n \"margin\": {\n \"top\": 123,\n \"bottom\": 123,\n \"left\": 123,\n \"right\": 123\n },\n \"pageRanges\": \"<string>\",\n \"displayHeaderFooter\": true,\n \"headerTemplate\": \"<string>\",\n \"footerTemplate\": \"<string>\",\n \"preferCSSPageSize\": true\n}"
response = http.request(request)
puts response.read_bodyOverview
Renders the session’s active page as a PDF via Chrome’sPage.printToPDF and returns the binary PDF in the response body. Response Content-Type is application/pdf.
Path Parameters
string
required
Browser session ID (UUID).
Body
string
Optional URL to navigate to before rendering. If omitted, the current page is printed.
string
Paper format. One of
Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6. When set, overrides paperWidth / paperHeight.boolean
default:"false"
Paper orientation.
boolean
default:"false"
Include background colors and images.
number
default:"1"
Render scale.
1 = 100%.number
default:"8.5"
Paper width in inches. Ignored when
format is set.number
default:"11"
Paper height in inches. Ignored when
format is set.string
One-based page ranges, e.g.
1-5, 8, 11-13.boolean
default:"false"
Display the header and footer templates.
string
HTML template for the header. Supports CSS classes
date, title, url, pageNumber, totalPages.string
HTML template for the footer. Same substitutions as
headerTemplate.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
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
Response
Success Response (200)
Binary PDF. Response headers:Content-Type: application/pdf
-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. |
Was this page helpful?
⌘I