TextBlock Class

Represents a formatted text document consisting of a series of Paragraphs, each laid out on a separate line and containing their own content in the form of Runs. You can change the content of the document by directly modifying the contents of its paragraphs, or via appendParagraph and appendRun. No word-wrapping is applied to the document unless a width greater than zero is specified.

@see TextAnnotation to position a text block as an annotation in 2d or 3d space.

Extends

Methods

Name Description
appendParagraph(): Paragraph Add and return a new paragraph.  
appendRun(run: Run): void Append a run to the last Paragraph in this block.  
applyStyle(styleName: string, options?: ApplyTextStyleOptions): void Apply the specified style to this block and - unless preventPropagation is true - to all of its paragraphs.  
clone(): TextBlock Create a deep copy of this component.  
equals(other: TextBlockComponent): boolean Returns true if this is equivalent to other.  
stringify(options?: TextBlockStringifyOptions): string Compute a string representation of the document's contents by concatenating the string representations of each of its paragraphs, separated by paragraphBreak.  
toJSON(): TextBlockProps Convert this component to its JSON representation.  
create(props: TextBlockProps): TextBlock Static Create a text block from its JSON representation.  
createEmpty(): TextBlock Static Create an empty text block containing no paragraphs and an empty styleName.  

Inherited methods

Name Inherited from Description
clearStyleOverrides(): void Inherited TextBlockComponent Reset any styleOverrides applied to this component's TextStyle.

Properties

Name Type Description
isEmpty Accessor ReadOnly boolean Returns true if every paragraph in this text block is empty.  
justification TextBlockJustification The alignment of the document's content.  
paragraphs Readonly Paragraph[] The ordered list of paragraphs within the document.  
width number The width of the document in meters.  

Inherited properties

Name Type Inherited from Description
overridesStyle Accessor Inherited ReadOnly boolean TextBlockComponent Returns true if styleOverrides specifies any deviations from this component's base TextStyle.
styleName Accessor Inherited string TextBlockComponent The name of the TextStyle that provides the base formatting for the contents of this component.
styleOverrides Accessor Inherited TextStyleSettingsProps TextBlockComponent Deviations in individual properties of the TextStyle specified by styleName.
For example, if the style uses the "Arial" font, you can override that by settings styleOverrides.fontName to "Comic Sans".

Defined in

Last Updated: 17 December, 2024