Authentication

Every request must be authenticated using your API key via HTTP Basic Auth.

Use your API key as the username and leave the password empty.

bash
curl -X POST https://api.webtopdfapi.com/convert/pdf \ -u "your_api_key:" \ -H "Content-Type: application/json" \ -d '{"source": "https://example.com"}'

You can also use the Authorization header directly:

Authorization: Basic base64(your_api_key:)

POST /convert/pdf

Convert a URL or raw HTML to a PDF document.

Endpoint: POST /convert/pdf

Request body (JSON):

ParameterTypeDefaultDescription
sourcestring*required*URL or raw HTML to convert
landscapebooleanfalseLandscape orientation
formatstring"A4"Paper format: A0-A5, Letter, Legal, Tabloid, Ledger
marginstring/object"10mm"Margins. String (`"10mm"`) or object (`{top, right, bottom, left}`)
cssstringCustom CSS to inject before rendering
javascriptstringCustom JS to execute before capture
delaynumber0Wait time in ms before generating (max 30000)
use_printbooleantrueEmulate `@media print` styles
disable_backgroundsbooleanfalseRemove background images and colors
zoomnumber1Zoom level (0.1 - 2)
filenamestringSets `Content-Disposition` filename
sandboxbooleanfalseSandbox mode (adds watermark, doesn't consume credits)
taggedbooleantrueGenerate accessible tagged PDF
outlinebooleantrueGenerate bookmarks from headings
page_rangesstringPage ranges, e.g. `"1-3, 5"`
viewport_widthnumber1280Browser viewport width in px
viewport_heightnumber1024Browser viewport height in px
timeoutnumber30000Navigation timeout in ms
wait_forstring"networkidle0"Wait strategy: `load`, `domcontentloaded`, `networkidle0`, `networkidle2`
wait_for_selectorstringWait for a CSS selector to appear

Headers & Footers:

ParameterTypeDescription
header.sourcestringHTML template for header
header.heightstringHeader height (e.g. `"50px"`)
footer.sourcestringHTML template for footer
footer.heightstringFooter height (e.g. `"50px"`)

Header/footer templates support these variables:
-
<span class="pageNumber"></span> — Current page number
-
<span class="totalPages"></span> — Total pages

Authentication for source URL:

ParameterTypeDescription
auth.usernamestringHTTP Basic auth username
auth.passwordstringHTTP Basic auth password
cookiesarrayCookies to set: `[{name, value, domain?, path?}]`

Orientation (Portrait / Landscape)

By default, PDFs are generated in portrait orientation. Set landscape: true for landscape.

Portrait (default):
``
json { "source": "https://example.com", "format": "A4", "landscape": false }

Landscape:
``
json { "source": "https://example.com", "format": "A4", "landscape": true }

Sandbox Mode

Use sandbox mode to test your integration without consuming credits. PDFs generated in sandbox mode have a watermark.

json
{ "source": "https://example.com", "sandbox": true }

Sandbox mode is perfect for:
- Testing your integration during development
- Validating PDF output before going live
- Debugging layout issues

Note: Sandbox PDFs include a watermark and should not be used in production.

Custom CSS & JavaScript

Inject custom CSS or JavaScript to modify the page before generating the PDF.

Inject CSS (e.g., hide elements, adjust styles):
``
json { "source": "https://example.com", "css": ".no-print, .cookie-banner { display: none !important; } body { font-size: 14px; }" }

Inject JavaScript (e.g., trigger rendering, expand sections):
``
json { "source": "https://example.com", "javascript": "document.querySelectorAll('details').forEach(d => d.open = true)" }

JavaScript runs before the PDF is generated, after the page has loaded.

Headers & Footers

Add custom HTML headers and footers to every page of the PDF.

json
{ "source": "https://example.com", "header": { "source": "<div style='font-size:10px; text-align:center; width:100%;'>My Company</div>", "height": "30px" }, "footer": { "source": "<div style='font-size:10px; text-align:center; width:100%;'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div>", "height": "30px" } }

Available variables in header/footer:
-
<span class="pageNumber"></span> — Current page number
-
<span class="totalPages"></span> — Total pages
-
<span class="date"></span> — Current date
-
<span class="title"></span> — Page title
-
<span class="url"></span> — Page URL

Waiting for Content

For pages with dynamic content (SPAs, lazy-loaded images, animations), you can configure how long to wait.

Wait for network idle:
``
json { "source": "https://my-spa.com", "wait_for": "networkidle0" }

Wait for a specific element:
``
json { "source": "https://my-spa.com", "wait_for_selector": "#content-loaded" }

Wait a fixed delay (ms):
``
json { "source": "https://my-spa.com", "delay": 3000 }

You can combine these options. The order is: page load → wait_for strategy → wait_for_selector → delay → generate PDF.

Credits & Pricing

Credits are consumed based on the size of the generated PDF:

PDF SizeCredits
Up to 5 MB1 credit
5 - 10 MB2 credits
10 - 15 MB3 credits
...+1 per 5 MB

Free tier: 50 credits/month (max 500 KB per PDF), renewed automatically. No credit card required.

Sandbox mode: Does not consume credits (adds watermark).

Checking your balance:
Your remaining credits are returned in the response headers:

X-Credits-Remaining: 47
X-Credits-Used: 1

Response

Success (200):
Returns the PDF as a binary stream with these headers:

Content-Type: application/pdf
Content-Disposition: inline; filename="output.pdf"
X-Credits-Remaining: 47
X-Credits-Used: 1

Errors:

StatusDescription
400Missing or invalid `source` parameter
401Invalid or missing API key
402Insufficient credits
500Conversion failed (check error message)

Error response body:
``
json { "error": "Bad Request", "message": "The 'source' parameter is required." }

Full Examples

cURL:
``
bash curl -X POST https://api.webtopdfapi.com/convert/pdf \ -u "sk_live_abc123...xyz:" \ -H "Content-Type: application/json" \ -d '{ "source": "https://example.com", "format": "A4", "landscape": true, "use_print": true, "css": ".no-print { display: none; }", "delay": 2000 }' \ -o report.pdf

Node.js:
``
javascript const response = await fetch("https://api.webtopdfapi.com/convert/pdf", { method: "POST", headers: { Authorization: Basic ${Buffer.from("sk_live_abc123...xyz:").toString("base64")}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
source: "https://example.com",
format: "A4",
landscape: true,
}),
});

const pdf = Buffer.from(await response.arrayBuffer());
fs.writeFileSync("report.pdf", pdf);

console.log("Credits remaining:", response.headers.get("x-credits-remaining"));
```

Python:
```python
import requests

response = requests.post(
"https://api.webtopdfapi.com/convert/pdf",
auth=("sk_live_abc123...xyz", ""),
json={
"source": "https://example.com",
"format": "A4",
"landscape": True,
"css": ".cookie-banner { display: none; }",
},
)

response.raise_for_status()

with open("report.pdf", "wb") as f:
f.write(response.content)

print(f"Credits remaining: {response.headers['x-credits-remaining']}")
```

n8n (HTTP Request node):
- Method: POST
- URL:
https://api.webtopdfapi.com/convert/pdf
- Authentication: Basic Auth (username = your API key, password = empty)
- Body: JSON with
source, format, etc.
- Response: Binary data → save or send as attachment