Skip to main content
This page collects the exported values, the type surface, page sizes, and the Vector primitive in one place.

Exports

The package exports the following values.
import {
  Doc,
  DocPage,
  Document,
  Page,
  Color,
  Theme,
  create_theme,
  Vector,
  vector,
  available_formula_fonts,
  default_formula_font,
  BaseElement,
  TextElement,
  RectElement,
  ImageElement,
  ContainerElement,
  TableElement,
  HeaderContainer,
  FooterContainer,
} from "@nemu-ai/pdf";
Doc and DocPage are the declarative API. Document and Page are the low level API. Color is the color utility, Theme and create_theme build themes, and Vector with vector are the spatial primitive. available_formula_fonts and default_formula_font describe the math fonts for LaTeX. The remaining names are the element classes used by the low level API.

Type exports

All of the following are exported as types.
import type {
  Block,
  Inline,
  InlineContent,
  DocOptions,
  PageConfig,
  PageContext,
  HeaderFooter,
  RawDraw,
  DrawArea,
  RoleStyles,
  StyleRole,
  TableCell,
  TableRow,
  ChartKind,
  ChartData,
  ChartSeries,
  ChartSlice,
  StyleProperties,
  DocumentOptions,
  PageSize,
  PageDimensions,
  MarginValues,
  ColorLike,
  ColorInput,
  ColorValue,
  ContainerLayout,
  FlexLayoutOptions,
  FlowLayoutOptions,
  CreateTextOptions,
  CreateRectOptions,
  CreateImageOptions,
  CreateTableOptions,
  CreateContainerOptions,
} from "@nemu-ai/pdf";

Page sizes

page_size accepts a named size or "Custom". The named sizes are measured in points.
NameWidth (pt)Height (pt)
A4595.28841.89
Letter612792
Legal6121008
Use custom_dimensions for any other size.
import { Document } from "@nemu-ai/pdf";

const pdf = new Document({ custom_dimensions: { width: 400, height: 600 } });

Vector

Vector is the spatial primitive for positions and sizes, and vector(x, y) is a convenience constructor. After build, elements expose get_position(), get_size(), and get_bbox().
import { Document, vector } from "@nemu-ai/pdf";

const v = vector(100, 200);

const pdf = new Document({ page_size: "A4", margin: 50 });
const page = pdf.create_page();
const label = page.text({ content: "Hello", position: { x: v.x, y: v.y } });
page.add(label);

await pdf.build("out.pdf");

label.get_position();
label.get_size();
label.get_bbox();

For LLMs

The package ships an llms.txt API map at its root. It is a single file that lists every exported type and signature, intended for code generation.

Color

Build a color from one input form and convert it to any other.

Introduction

How the declarative and low level APIs relate.