POST /v1/pdf
Docs · OG · PDF · Screenshot · Signed URLs · Errors · Limits
Examples
Exactly one of url or html is required. The response is the PDF.
curl
curl -X POST https://render.starhold.app/v1/pdf \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"html":"<h1>Invoice 42</h1><p>Thank you.</p>","page_size":"A4"}' \
-o out.pdf
JavaScript (fetch)
import { writeFile } from "node:fs/promises";
const res = await fetch("https://render.starhold.app/v1/pdf", {
method: "POST",
headers: { Authorization: "Bearer YOUR_API_KEY", "Content-Type": "application/json" },
body: '{"html":"<h1>Invoice 42</h1><p>Thank you.</p>","page_size":"A4"}',
});
if (!res.ok) throw new Error((await res.json()).error.message);
await writeFile("out.pdf", Buffer.from(await res.arrayBuffer()));
Python (requests)
import requests
body = '{"html":"<h1>Invoice 42</h1><p>Thank you.</p>","page_size":"A4"}'
res = requests.post("https://render.starhold.app/v1/pdf",
headers={"Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json"},
data=body.encode(), timeout=35)
res.raise_for_status()
open("out.pdf", "wb").write(res.content)
PHP (curl ext)
<?php
$body = '{"html":"<h1>Invoice 42</h1><p>Thank you.</p>","page_size":"A4"}';
$ch = curl_init("https://render.starhold.app/v1/pdf");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => ["Authorization: Bearer YOUR_API_KEY", "Content-Type: application/json"],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 35,
]);
$out = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) { die($out); }
file_put_contents("out.pdf", $out);
Go (net/http)
package main
import (
"io"
"net/http"
"os"
"strings"
"time"
)
func main() {
body := `{"html":"<h1>Invoice 42</h1><p>Thank you.</p>","page_size":"A4"}`
req, _ := http.NewRequest("POST", "https://render.starhold.app/v1/pdf", strings.NewReader(body))
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
res, err := (&http.Client{Timeout: 35 * time.Second}).Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
if res.StatusCode != 200 {
io.Copy(os.Stderr, res.Body)
os.Exit(1)
}
out, _ := os.Create("out.pdf")
io.Copy(out, res.Body)
}
Fields
| Field | Type and range | Default |
|---|---|---|
url or html | exactly one; html up to 512 KB; css goes with html | none |
page_size | A4, Letter, Legal, A3, A5, Tabloid | A4 |
width, height | CSS lengths, given together, instead of page_size | none |
landscape | true or false | false |
margin | top, right, bottom, left as CSS lengths, each at most 100mm | 10mm each |
header_html, footer_html | up to 16 KB each; classes pageNumber, totalPages, date, title, url | off |
print_background | true or false | true |
scale | 0.1 to 2.0 | 1.0 |
page_ranges | for example 1-3,5 | all |
media | print or screen | print |
wait_until | load, domcontentloaded or networkidle | load |
wait_for | a CSS selector, up to 256 characters | none |
delay_ms | 0 to 10,000 | 0 |
cache_ttl | 0 to 86,400 seconds | 3,600 for url, 86,400 for html |
A PDF may be up to 20 MB and 200 pages. More returns output_too_large.