An advanced text layout framework for complex typography in PDF generation
—
Core utilities for creating styled text. AttributedString is the fundamental data structure representing text with styling attributes applied to specific ranges.
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);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