better docx
UsageParagraph

Symbol Runs

SymbolRuns require an understanding of Paragraphs.

You can add multiple symbol runs in Paragraphs along with text runs using the Paragraph's children property.

import { Paragraph, TextRun, SymbolRun } from "betterdocx";

const paragraph = new Paragraph({
    children: [new TextRun("This is a checkbox: "), new SymbolRun("F071")],
});

Specifying symbol font

By default symbol runs will use the Wingdings font. To switch fonts, pass an object instead of a string to the SymbolRun constructor and specify char and symbolFont properties:

const symbol = new SymbolRun({
    char: "F071",
    symbolFont: "Arial",
});

Example symbols

Symbols are specified by their hexidecimal code. Ref http://officeopenxml.com/WPtextSpecialContent-symbol.php. Below are some examples.

  • F071: empty checkbox
  • F043: thumbs up
  • F04A: smile
  • F04C: frown
  • F022: scissors
  • F0F0: right arrow
  • F0FE: checked box

Run formatting

Beyond char and symbolFont, SymbolRun accepts the full set of run options available on text runs — size, color, font, underline, bold, italics, highlight, break, and so on. For example:

const symbol = new SymbolRun({
    char: "F071",
    bold: true,
    italics: true,
    size: 48, // half-points, so 24pt
    color: "FF0000",
    underline: {
        type: UnderlineType.SINGLE,
        color: "0000FF",
    },
    highlight: "yellow",
});

See the text run documentation for the full list of run options.

On this page