Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/pinchtab/pinchtab/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The PDF API exports web pages to PDF format with customizable options for:
  • Page size and orientation
  • Margins
  • Headers and footers
  • Page ranges
  • Accessibility features

Export to PDF

GET /tabs/{id}/pdf
POST /tabs/{id}/pdf
curl "http://localhost:9867/tabs/tab_abc123/pdf" > output.pdf

Query Parameters (GET)

landscape
boolean
default:"false"
Landscape orientation
scale
number
default:"1.0"
Print scaling factor (0.1-2.0)
paperWidth
number
default:"8.5"
Paper width in inches
paperHeight
number
default:"11"
Paper height in inches
marginTop
number
default:"0"
Top margin in inches
marginBottom
number
default:"0"
Bottom margin in inches
marginLeft
number
default:"0"
Left margin in inches
marginRight
number
default:"0"
Right margin in inches
pageRanges
string
Page ranges to print (e.g., “1-3,5,8-10”)
Show header and footer
headerTemplate
string
HTML template for header
HTML template for footer
generateTaggedPDF
boolean
default:"false"
Generate accessible/tagged PDF
generateDocumentOutline
boolean
default:"false"
Generate document outline (bookmarks)
output
string
Set to json for base64-encoded PDF or file to save to disk

Request Body (POST)

Same parameters as query params, but sent as JSON:
{
  "landscape": true,
  "paperWidth": 11,
  "paperHeight": 8.5,
  "marginTop": 0.5,
  "marginBottom": 0.5,
  "marginLeft": 0.5,
  "marginRight": 0.5,
  "scale": 0.9,
  "displayHeaderFooter": true,
  "headerTemplate": "<div style='font-size:10px;text-align:center;width:100%'>Page <span class='pageNumber'></span></div>",
  "footerTemplate": "<div style='font-size:10px;text-align:center;width:100%'><span class='url'></span></div>"
}

Response

Returns PDF binary data with Content-Type: application/pdf header.

Paper Sizes

Common paper sizes in inches:
SizeWidth × HeightUse Case
Letter8.5 × 11US standard
Legal8.5 × 14US legal documents
A48.27 × 11.69International standard
A311.69 × 16.54Large format
Tabloid11 × 17Posters, large prints

Examples

# Letter (default)
curl "http://localhost:9867/tabs/tab_abc123/pdf" > letter.pdf

# A4
curl "http://localhost:9867/tabs/tab_abc123/pdf?paperWidth=8.27&paperHeight=11.69" > a4.pdf

# Legal
curl "http://localhost:9867/tabs/tab_abc123/pdf?paperWidth=8.5&paperHeight=14" > legal.pdf

Headers and Footers

Add custom headers and footers with HTML templates:
import requests

resp = requests.post(
    "http://localhost:9867/tabs/tab_abc123/pdf",
    json={
        "displayHeaderFooter": True,
        "marginTop": 1,
        "marginBottom": 1,
        "headerTemplate": """
            <div style='font-size:10px; text-align:center; width:100%;'>
                <span class='title'></span> - Page <span class='pageNumber'></span> of <span class='totalPages'></span>
            </div>
        """,
        "footerTemplate": """
            <div style='font-size:9px; text-align:center; width:100%;'>
                <span class='url'></span> | Generated on <span class='date'></span>
            </div>
        """
    }
)

with open("output.pdf", "wb") as f:
    f.write(resp.content)

Template Variables

VariableDescription
<span class='title'></span>Document title
<span class='url'></span>Page URL
<span class='date'></span>Print date
<span class='pageNumber'></span>Current page number
<span class='totalPages'></span>Total pages

Page Ranges

Export specific pages only:
# Pages 1-3
curl "http://localhost:9867/tabs/tab_abc123/pdf?pageRanges=1-3" > pages-1-3.pdf

# Pages 1, 3, and 5-7
curl "http://localhost:9867/tabs/tab_abc123/pdf?pageRanges=1,3,5-7" > selected-pages.pdf

# First page only
curl "http://localhost:9867/tabs/tab_abc123/pdf?pageRanges=1" > first-page.pdf

Base64 Output

Get PDF as base64-encoded JSON:
curl "http://localhost:9867/tabs/tab_abc123/pdf?output=json" | jq .
Response:
{
  "format": "pdf",
  "base64": "JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9UeXBlL..."
}
Decode in Python:
import base64

resp = requests.get(
    "http://localhost:9867/tabs/tab_abc123/pdf?output=json"
)
pdf_data = base64.b64decode(resp.json()["base64"])

with open("output.pdf", "wb") as f:
    f.write(pdf_data)

Save to File

Save PDF directly to disk:
curl "http://localhost:9867/tabs/tab_abc123/pdf?output=file"
Response:
{
  "path": "/path/to/pdfs/output-20260303-123456.pdf",
  "size": 125678,
  "format": "pdf",
  "timestamp": "20260303-123456"
}

Complete Example

import requests
import time

BASE = "http://localhost:9867"

# Start instance
inst = requests.post(f"{BASE}/instances/start",
    json={"mode": "headed"}).json()

# Open tab
tab = requests.post(f"{BASE}/instances/{inst['id']}/tabs/open",
    json={"url": "https://example.com"}).json()

tab_id = tab["tabId"]

# Wait for page load
time.sleep(2)

# Export to PDF with custom options
resp = requests.post(f"{BASE}/tabs/{tab_id}/pdf", json={
    "landscape": False,
    "paperWidth": 8.5,
    "paperHeight": 11,
    "marginTop": 0.5,
    "marginBottom": 0.5,
    "marginLeft": 0.5,
    "marginRight": 0.5,
    "scale": 1.0,
    "displayHeaderFooter": True,
    "headerTemplate": "<div style='font-size:10px;text-align:center;width:100%;'>Example Domain</div>",
    "footerTemplate": "<div style='font-size:10px;text-align:center;width:100%;'>Page <span class='pageNumber'></span></div>",
    "generateTaggedPDF": True,
    "generateDocumentOutline": True
})

# Save PDF
with open("example.pdf", "wb") as f:
    f.write(resp.content)

print(f"PDF saved: {len(resp.content)} bytes")

# Cleanup
requests.post(f"{BASE}/instances/{inst['id']}/stop")

Batch Export Example

#!/bin/bash

BASE="http://localhost:9867"
TAB="tab_abc123"

URLS=(
  "https://example.com"
  "https://google.com"
  "https://github.com"
)

for url in "${URLS[@]}"; do
  # Navigate
  curl -s -X POST "$BASE/tabs/$TAB/navigate" \
    -d "{\"url\":\"$url\",\"waitFor\":\"networkidle\"}"
  
  sleep 3
  
  # Export to PDF
  NAME=$(echo $url | sed 's/https:\/\///' | sed 's/\//_/g')
  curl -s "$BASE/tabs/$TAB/pdf?landscape=true&marginTop=0.5" \
    > "${NAME}.pdf"
  
  echo "Saved ${NAME}.pdf"
done

Error Handling

Tab Not Found (404)

curl "http://localhost:9867/tabs/nonexistent/pdf"
Response:
{
  "error": "tab not found",
  "statusCode": 404
}

Invalid Parameters (400)

curl "http://localhost:9867/tabs/tab_abc123/pdf?scale=5.0"
Response:
{
  "error": "scale must be between 0.1 and 2.0",
  "statusCode": 400
}

Best Practices

Wait for Page Load

# Navigate with wait
requests.post(f"{BASE}/tabs/{tab_id}/navigate",
    json={"url": "https://example.com", "waitFor": "networkidle"})

# Then export
resp = requests.get(f"{BASE}/tabs/{tab_id}/pdf")

Use Margins for Readability

{
  "marginTop": 0.5,
  "marginBottom": 0.5,
  "marginLeft": 0.75,
  "marginRight": 0.75
}

Enable Accessibility

{
  "generateTaggedPDF": true,
  "generateDocumentOutline": true
}

Adjust Scale for Fit

# If content is cut off, reduce scale
resp = requests.post(f"{BASE}/tabs/{tab_id}/pdf",
    json={"scale": 0.8})

Next Steps

Screenshots

Capture visual snapshots

Screencast

Stream live tab content

Navigation

Navigate pages before export

Snapshot

Get structured page data