better docx
Usage

Checkboxes

Checkboxes requires an understanding of Paragraphs.

CheckBox creates a checkbox content control. It is used as a child of a Paragraph:

import { CheckBox, Document, Paragraph, TextRun } from "betterdocx";

const doc = new Document({
    sections: [
        {
            children: [
                new Paragraph({
                    children: [
                        new TextRun("Accept terms and conditions "),
                        new CheckBox({ checked: true }),
                    ],
                }),
            ],
        },
    ],
});

By default the checkbox is unchecked and rendered with the MS Gothic font, using (U+2610) for the unchecked state and (U+2612) for the checked state.

Options

All options are optional — new CheckBox() produces an unchecked box with the default glyphs.

PropertyTypeNotesPossible Values
aliasstringOptionalA friendly name for the content control, e.g. "Are you ok?"
checkedbooleanOptionalWhether the checkbox starts checked. Defaults to false
checkedState{ value?: string, font?: string }OptionalGlyph for the checked state. value is a hex character code (e.g. "2611"), font defaults to "MS Gothic"
uncheckedState{ value?: string, font?: string }OptionalGlyph for the unchecked state. value is a hex character code (e.g. "2610"), font defaults to "MS Gothic"

Custom glyphs

The value of each state is the hexadecimal code of the character to display. For example, to use (U+2611) instead of the default for the checked state:

new Paragraph({
    children: [
        new CheckBox({
            checked: true,
            checkedState: { value: "2611", font: "MS Gothic" },
            uncheckedState: { value: "2610", font: "MS Gothic" },
        }),
    ],
});

On this page