Skip to main content
A theme centralizes named colors and applies default styles by element type and by classname. Build one with create_theme, then attach it per page or document wide.

Creating a theme

create_theme(name: string, definition?): Theme
The optional definition holds a colors map of named colors, along with other optional fields.
import { Document, create_theme } from "@nemu-ai/pdf";

const theme = create_theme("brand", {
  colors: { primary: "#1a365d", muted: "#718096", accent: "#3182ce" },
});

Applying a theme

Apply a theme document wide with set_theme, or pass it to a single page through create_page.
const pdf = new Document({ page_size: "A4", margin: 50 });
pdf.set_theme(theme);
const page = pdf.create_page(theme);

Reading colors

theme.get_color returns a registered color by name. Use it anywhere a color is accepted.
theme.get_color("primary");

page.add(
  page.text({
    content: "Heading",
    style: { color: theme.get_color("primary") },
  }),
  page.text({
    content: "Subtle note",
    style: { color: theme.get_color("muted") },
  }),
);
Define every brand color once in create_theme, then reference it with get_color so a single edit updates the whole document.

Elements

Apply theme colors to text, rectangles, and images.

Overview

The Document and Page classes and the build pipeline.