# HTML to PDF API for any URL

> Any URL to a print-ready PDF. Rendered through a real browser behind residential proxies.

- Endpoint: `POST https://scrapenest.dev/v1/scrape/pdf`
- Price: 25 / 35 credits
- Category: Utilities
- Reference: https://scrapenest.dev/docs#ep-pdf
- Web page: https://scrapenest.dev/catalog/pdf
- Updated: 2026-11-04

Point us at a URL and get back a base64-encoded PDF rendered through a real headless browser behind residential proxies. Pick the paper size, portrait or landscape, and the viewport. We handle the browser and the proxy so you never run or babysit one yourself.

## The hard part

A faithful PDF in production means running a headless browser, waiting for the page to actually settle, clearing anti-bot walls, and picking the right paper geometry — then keeping that browser fleet alive. You send a URL and a paper size; we return the bytes.

## PDF API: what you get

- Paper sizes: Letter, Legal, Tabloid, Ledger, and A0–A6. `landscape=true` for wide content.
- `viewport_width`/`viewport_height` control page layout before pagination.
- `cookies` and `headers` render authenticated or gated pages; `session_id` reuses a sticky residential exit IP for multi-step flows.
- `wait_extra_ms` waits out late-loading SPA content before capture.
- Base64 returned inline (no S3 round-trip, no presigned-URL dance).
- Failures and timeouts don't bill.

## PDF API use cases

- **Archive articles and pages**: Save a print-ready copy of a page as it looked on the day you captured it.
- **Invoices and receipts**: Render a logged-in receipt or invoice page to PDF by sending its `cookies`.
- **Reports from web dashboards**: Turn a web report into a landscape PDF so wide tables fit the page.

## PDF API quickstart

Install an SDK with `pip install scrapenest` or `npm install scrapenest`, or call the HTTP API directly with your key in the `Authorization: Bearer` header. No key yet? Sign up free at https://scrapenest.dev/signup, verify your email, then create a key in your dashboard.

### Python SDK

```python
import os
from scrapenest import Client

client = Client(os.environ["SCRAPENEST_API_KEY"], timeout=120)
doc = client.pdf("https://stripe.com/docs/api", format="A4")
doc.save("page.pdf")
print(doc.bytes, "bytes,", doc.format, doc.credits_charged, "credits")
```

### Node SDK

```javascript
import { writeFileSync } from "node:fs";
import { ScrapeNest } from "scrapenest";

const client = new ScrapeNest({ apiKey: process.env.SCRAPENEST_API_KEY, timeout: 120_000 });
const doc = await client.pdf({ url: "https://stripe.com/docs/api", format: "A4" });
writeFileSync("page.pdf", Buffer.from(doc.pdf_base64, "base64"));
console.log(doc.bytes, "bytes,", doc.format, doc.credits_charged, "credits");
```

### curl

```bash
curl -X POST https://scrapenest.dev/v1/scrape/pdf \
  -H "Authorization: Bearer sn_••••" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://stripe.com/docs/api", "format": "A4" }' \
  | jq -r .pdf_base64 | base64 -d > page.pdf
```

### Python (httpx)

```python
import base64, httpx

r = httpx.post(
    "https://scrapenest.dev/v1/scrape/pdf",
    headers={"Authorization": "Bearer sn_••••"},
    json={"url": "https://stripe.com/docs/api", "format": "A4"},
    timeout=120,
)
r.raise_for_status()
data = r.json()
with open("page.pdf", "wb") as f:
    f.write(base64.b64decode(data["pdf_base64"]))
print(f"{data['bytes']} bytes, {data['format']}")
```

### JavaScript (fetch)

```javascript
import { writeFileSync } from "node:fs";

const r = await fetch("https://scrapenest.dev/v1/scrape/pdf", {
  method: "POST",
  headers: {
    "Authorization": "Bearer sn_••••",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ url: "https://stripe.com/docs/api", format: "A4" }),
});
const data = await r.json();
writeFileSync("page.pdf", Buffer.from(data.pdf_base64, "base64"));
```

### Go

```go
package main

import (
    "bytes"
    "encoding/base64"
    "encoding/json"
    "net/http"
    "os"
)

func main() {
    body, _ := json.Marshal(map[string]any{
        "url":    "https://stripe.com/docs/api",
        "format": "A4",
    })
    req, _ := http.NewRequest("POST",
        "https://scrapenest.dev/v1/scrape/pdf", bytes.NewReader(body))
    req.Header.Set("Authorization", "Bearer sn_••••")
    req.Header.Set("Content-Type", "application/json")
    resp, _ := http.DefaultClient.Do(req)
    defer resp.Body.Close()
    var out struct{ PdfBase64 string `json:"pdf_base64"` }
    json.NewDecoder(resp.Body).Decode(&out)
    pdf, _ := base64.StdEncoding.DecodeString(out.PdfBase64)
    os.WriteFile("page.pdf", pdf, 0644)
}
```

## PDF API request and response

### Request body

```json
{
  "url": "https://stripe.com/docs/api",
  "format": "A4"
}
```

### Response

```json
{
  "url": "https://stripe.com/docs/api",
  "final_url": "https://stripe.com/docs/api",
  "status_code": 200,
  "proxy_used": "residential",
  "elapsed_ms": 4120,
  "format": "A4",
  "landscape": false,
  "bytes": 248913,
  "pdf_base64": "JVBERi0xLjcKJ…",
  "cache_hit": false,
  "credits_charged": 25
}
```

Fields with no value are left out of the JSON rather than sent as `null`, so read optional fields defensively. `proxy_used` is the exception: it is always present, `null` included.

## PDF API pricing

25 credits for a standard render; 35 credits for landscape or large paper (Tabloid, Ledger, A0–A2). Cache hits bill at 1 credit. Failures don't bill.

- Large or landscape formats (Tabloid, Ledger, A0–A2) bill at 35 credits; standard portrait sizes bill at 25.
- A render that takes longer than 20 seconds streams keepalive bytes so the connection stays open. One render gets 75 seconds across every tier; past that it fails with `pdf_failed` and nothing is billed.

## PDF API limits

- Paper: Letter (default), Legal, Tabloid, Ledger and A0 to A6. `landscape` must be a JSON boolean.
- Viewport: 320 to 3840 by 240 to 2160, default 1280 × 720. `wait_extra_ms`: up to 10,000.
- One render gets 75 seconds across every tier. Past 20 seconds the response streams, so a later error arrives inside the 200 body.
- Caching is off unless you set `cache_ttl_seconds`. Requests with `cookies`, `headers` or `session_id` are never cached.

## PDF API error codes

| HTTP | Code | Meaning |
| --- | --- | --- |
| 422 | `target_error` | The target returned an error status, or its host doesn't resolve in DNS. |
| 503 | `pdf_failed` | The render failed or ran past 75 seconds. Not billed. |
| 503 | `connection_failed` | The DNS lookup failed temporarily. Retry with backoff. |
| 400 | `unsafe_url` | The URL is malformed or points at a private host. |
| 400 | `redirect_to_unsafe_url` | The page redirected to a private address. |

Every endpoint can also return `401 unauthorized` (missing or wrong key), `402 insufficient_credits` (balance used up), `403 email_not_verified` (an email signup must verify its address before its key works) and `429 rate_limited` or `concurrency_limit_exceeded`. All errors share one JSON envelope; see the [error reference](https://scrapenest.dev/docs#errors).

## PDF API FAQ

### Which paper sizes are supported?

Letter (the default), Legal, Tabloid, Ledger and A0 through A6, in portrait or with `landscape: true`.

### What does a PDF cost?

25 credits for a standard size in portrait, and 35 for landscape or the large sizes (Tabloid, Ledger, A0 to A2). A cache hit bills 1, and failed renders bill nothing.

### Can I render a page behind a login?

Yes. Pass `cookies` and `headers`, and reuse a `session_id` to keep the same exit IP across calls.

### How do I save the file?

The PDF comes back base64-encoded in `pdf_base64`. Decode it and write the bytes; in the Python SDK the response has a `save(path)` helper.

## Related endpoints

- [Website screenshot API](https://scrapenest.dev/catalog/screenshot.md): `POST /v1/scrape/screenshot`. Capture a screenshot of any public URL and get back base64-encoded PNG or JPEG. Viewport or full-page, with auto-fallback for hostile sites.
- [Web scraping API for any URL](https://scrapenest.dev/catalog/scrape-url.md): `POST /v1/scrape/url`. Point us at a page. We get past the wall and hand back the rendered HTML and clean text.
- [Batch scraping API](https://scrapenest.dev/catalog/scrape-batch.md): `POST /v1/scrape/batch`. Fetch up to 10 URLs in a single request — the same engine as Any URL, run concurrently.

## Get 1,000 free credits

Every account starts on the Free plan: 1,000 credits a month, no card. Verify your email, then mint an API key and make this call. Sign up at https://scrapenest.dev/signup.
