CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-react-pdf--textkit

An advanced text layout framework for complex typography in PDF generation

Pending
Overview
Eval results
Files

attributed-string.mddocs/

AttributedString Utilities

Core utilities for creating styled text. AttributedString is the fundamental data structure representing text with styling attributes applied to specific ranges.

Capabilities

String Creation

Create attributed strings from text fragments with styling information.

/**
 * Create attributed string from text fragments
 * @param fragments - Array of text fragments with optional attributes
 * @returns Complete attributed string with merged runs
 */
function fromFragments(fragments: Fragment[]): AttributedString;

Usage Example:

import { fromFragments } from "@react-pdf/textkit";

const fragments = [
  { string: "Hello ", attributes: { fontSize: 16, color: "black" } },
  { string: "World", attributes: { fontSize: 18, color: "blue" } },
  { string: "!", attributes: { fontSize: 16, color: "red" } }
];

const attributedString = fromFragments(fragments);

Core Types

interface AttributedString {
  string: string;
  syllables?: string[];
  runs: Run[];
  box?: Rect;
  decorationLines?: DecorationLine[];
  overflowLeft?: number;
  overflowRight?: number;
  xAdvance?: number;
  ascent?: number;
}

interface Fragment {
  string: string;
  attributes?: Attributes;
}

interface Run {
  start: number;
  end: number;
  attributes: Attributes;
  glyphIndices?: number[];
  glyphs?: Glyph[];
  positions?: Position[];
  xAdvance?: number;
  height?: number;
  descent?: number;
}

Install with Tessl CLI

npx tessl i tessl/npm-react-pdf--textkit

docs

attributed-string.md

decoration-script.md

engines.md

index.md

layout-engine.md

tile.json