Examples

Five complete documents. Each one shows the HTML first, then how to render it with the API, the WebAssembly build and the native binary. The engine is the same in all three, so the output is too.

Invoice

A one-page A4 PDF. @page sets the paper and its margins; the pagination option makes the engine honor it. The width and height, 794 × 1123, are A4 in CSS pixels: the height is required as soon as you paginate.

invoice.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
  @page { size: A4; margin: 18mm; }
  body { font: 10.5pt/1.5 Body, sans-serif; color: #1c2434; margin: 0; }
  header { display: flex; justify-content: space-between; align-items: baseline;
           border-bottom: 2px solid #2447b3; padding-bottom: 8pt; }
  h1 { font-size: 20pt; margin: 0; color: #2447b3; }
  table { width: 100%; border-collapse: collapse; margin-top: 24pt; }
  th, td { padding: 6pt 0; border-bottom: 1px solid #d5dbe8; text-align: left; }
  th:last-child, td:last-child { text-align: right; }
  tfoot td { border: 0; font-weight: bold; }
</style>
</head>
<body>
  <header><h1>Invoice</h1><span>No. 2026-0042 · 15 November 2026</span></header>
  <p>Billed to <strong>Northwind Books</strong>, 12 Quay Street, Galway</p>
  <table>
    <thead><tr><th>Description</th><th>Qty</th><th>Amount</th></tr></thead>
    <tbody>
      <tr><td>Typesetting, 320 pages</td><td>1</td><td>€1,600.00</td></tr>
      <tr><td>Cover design</td><td>1</td><td>€450.00</td></tr>
    </tbody>
    <tfoot><tr><td colspan="2">Total</td><td>€2,050.00</td></tr></tfoot>
  </table>
</body>
</html>
invoice.ts
import { readFile, writeFile } from "node:fs/promises";

const response = await fetch("https://api.palatine.page/v1/render", {
  method: "POST",
  headers: {
    Authorization: "Bearer " + process.env.PALATINE_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    html: await readFile("invoice.html", "utf8"),
    format: "pdf",
    width: 794,
    height: 1123,
    options: { pagination: true, pdfTitle: "Invoice 2026-0042" },
  }),
});
if (!response.ok) throw new Error((await response.json()).error);

await writeFile("invoice.pdf", new Uint8Array(await response.arrayBuffer()));

The API does not know a font called Body, so the text falls back to the built-in Noto Sans. To use your own font, publish the file and declare it in the document's CSS:

@font-face {
  font-family: Body;
  src: url("https://example.com/fonts/Body.woff2");
}

Paginated report

A small book: each chapter starts a page, its title runs in the page header, pages are numbered, a footnote sits at the bottom of its page, and a table of contents lists the page of each chapter. Paragraphs are justified with Knuth–Plass line breaking and automatic hyphenation.

report.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
  @page {
    size: A5;
    margin: 20mm 16mm 22mm;
    @top-center { content: string(chapter); font: italic 9pt Body; }
    @bottom-center { content: counter(page) " / " counter(pages); font: 9pt Body; }
    @footnote { border-top: 0.5pt solid #777; padding-top: 4pt; }
  }
  @page :first { @top-center { content: none; } }

  body { font: 10.5pt/1.45 Body, serif; }
  h1 { string-set: chapter content(); break-before: page; font-size: 18pt; }
  h1:first-of-type { break-before: auto; }
  p { text-align: justify; text-indent: 1.2em; margin: 0;
      hyphens: auto; widows: 2; orphans: 2; }
  h1 + p { text-indent: 0; }
  .note { float: footnote; font-size: 8.5pt; }

  nav a { display: block; color: inherit; text-decoration: none; }
  nav a::after { content: " · " target-counter(attr(href url), page); }
</style>
</head>
<body>
  <nav data-palatine-toc="h1"></nav>

  <h1 id="tides">Tides</h1>
  <p>The harbour empties twice a day<span class="note">Measured at the
     north pier.</span> and the boats settle on the sand.</p>
  <p>…</p>

  <h1 id="weather">Weather</h1>
  <p>Wind from the south-west brings rain by evening.</p>
  <p>…</p>
</body>
</html>
  • string-set and string() carry the chapter title into the @top-center margin box.
  • float: footnote moves the note to the foot of the page and leaves a numbered call in the text.
  • data-palatine-toc fills the element with links to the selected headings; target-counter() prints the page each link points to.
  • hyphens: auto follows the document language, set by lang.
report.ts
import { readFile, writeFile } from "node:fs/promises";

const response = await fetch("https://api.palatine.page/v1/render", {
  method: "POST",
  headers: {
    Authorization: "Bearer " + process.env.PALATINE_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    html: await readFile("report.html", "utf8"),
    format: "pdf",
    width: 559,
    height: 794,
    options: {
      pagination: true,
      pdfTitle: "Field Notes",
      typography: { justification: { algorithm: "knuth-plass" } },
    },
  }),
});
if (!response.ok) throw new Error((await response.json()).error);

console.log(response.headers.get("x-palatine-pages"), "pages");
await writeFile("report.pdf", new Uint8Array(await response.arrayBuffer()));

A PDF of any length is billed as one document. The page count comes back in x-palatine-pages.

The size, 559 × 794, is A5 in CSS pixels. The articles on paged media and footnotes and references go further.

Social card image

The same engine draws images. Set the format to png or webp and give the exact size in pixels. Flexbox, grid and gradients work as in a browser.

card.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
  body { margin: 0; width: 1200px; height: 630px; box-sizing: border-box;
         display: flex; flex-direction: column; justify-content: center;
         padding: 80px; color: white; font-family: Body, sans-serif;
         background: linear-gradient(135deg, #14213d, #2447b3); }
  h1 { font-size: 72px; line-height: 1.1; margin: 0 0 24px; }
  p { font-size: 30px; margin: 0; opacity: .8; }
</style>
</head>
<body>
  <h1>Paged media, without a browser</h1>
  <p>palatine.page/articles</p>
</body>
</html>
terminal
curl --fail-with-body https://api.palatine.page/v1/render \
  --header "Authorization: Bearer $PALATINE_API_KEY" \
  --header "Content-Type: application/json" \
  --data "$(jq -n --rawfile html card.html \
    '{ html: $html, format: "png", width: 1200, height: 630 }')" \
  --output card.png

jq puts the HTML file into the JSON body with the right escaping. An image counts as one document, like a PDF.

Images, stylesheets and fonts

A document that links to other files: a stylesheet, a logo, and a second font declared with @font-face. The engine never opens a file or a URL by itself. Each target has its own way to hand these resources over.

letter.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="theme.css">
</head>
<body>
  <img src="assets/logo.png" alt="Northwind Books">
  <h1>Welcome aboard</h1>
  <p>Your account is ready.</p>
</body>
</html>
theme.css
@font-face { font-family: Display; src: url("fonts/Display.ttf"); }

body { font: 11pt/1.5 Body, sans-serif; margin: 48px; }
h1 { font-family: Display, sans-serif; font-size: 24pt; }
img { width: 96px; }
letter.ts
import { readFile, writeFile } from "node:fs/promises";

const response = await fetch("https://api.palatine.page/v1/render", {
  method: "POST",
  headers: {
    Authorization: "Bearer " + process.env.PALATINE_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    html: await readFile("letter.html", "utf8"),
    format: "pdf",
    width: 794,
    // theme.css, assets/logo.png and fonts/Display.ttf are fetched under this URL.
    baseURL: "https://example.com/letters/",
  }),
});
if (!response.ok) throw new Error((await response.json()).error);

await writeFile("letter.pdf", new Uint8Array(await response.arrayBuffer()));

The API fetches resources over http(s), so they must be reachable from the internet. Without baseURL, a relative URL cannot be fetched and the render fails with 422. Private network addresses are refused.

Download in the browser

With the WebAssembly build, the PDF is made on your user's device: nothing is uploaded and no server renders. This example runs the engine in a Web Worker so the page stays responsive, shows the progress, then saves the file.

index.html
<article id="report">
  <h1>Quarterly report</h1>
  <p>Revenue grew by 12%.</p>
  <img src="/logo.png" width="48" alt="Logo">
</article>

<button id="download">Download PDF</button>
<span id="status"></span>
WebAssembly only
main.ts
import { createWorkerRenderer } from "@palatine/renderer/browser";

const worker = new Worker(
  new URL("@palatine/renderer/worker", import.meta.url),
  { type: "module" },
);
// A domain-bound license (PAL2-…): safe to ship, it only works on your domains.
const palatine = createWorkerRenderer(worker, { license: "PAL2-…" });

const font = new Uint8Array(await (await fetch("/fonts/Body.ttf")).arrayBuffer());
const status = document.querySelector("#status");

document.querySelector("#download").addEventListener("click", async () => {
  await palatine.download(
    {
      html: document.querySelector("#report").outerHTML,
      css: "@page { size: A4; margin: 20mm } body { font: 11pt/1.5 Body }",
      format: "pdf",
      width: 794,
      height: 1123,
      fonts: [{ family: "Body", data: font }],
      resources: "fetch", // images and stylesheets are fetched from the worker
      baseURL: location.href,
      options: { pagination: true },
    },
    "report.pdf",
    {
      onProgress: (progress) => {
        if (progress.phase === "pages")
          status.textContent = progress.painted + " / " + progress.total + " pages";
      },
      onWarning: (warning) => console.warn(warning.code, warning.message),
    },
  );
  status.textContent = "Done";
});

Vite bundles the worker from this new URL(…) form. A license shipped to a public page can be read by anyone, which is why web apps use a license bound to their domains: see domain authorization. The browser notes cover rendering without a worker and returning bytes or a Blob instead of a download.