For the complete documentation index, see llms.txt. This page is also available as Markdown.

Formatting

Formatting and styling Word documents with BoxLang — fonts, alignment, spacing, page setup

Control the visual appearance of your Word documents with rich formatting options.


Paragraph Formatting

Alignment

Control text alignment within paragraphs:

word()
    .addParagraph( "Left-aligned (default)", { alignment: "LEFT" } )
    .addParagraph( "Centered text", { alignment: "CENTER" } )
    .addParagraph( "Right-aligned text", { alignment: "RIGHT" } )
    .addParagraph( "Justified text fills the line width evenly on both sides.", { alignment: "JUSTIFY" } )
    .save( "alignment.docx" )

Spacing

Control space before/after paragraphs and line height:

word()
    .addParagraph( "Paragraph with extra space below.", {
        spacingAfter: 240    // 240 twips ≈ 12pt
    } )
    .addParagraph( "Double-spaced paragraph.", {
        lineSpacing: 480     // 480 twips = double spacing
    } )
    .addParagraph( "1.5 line spacing with indent.", {
        lineSpacing: 360,    // 360 twips = 1.5 spacing
        spacingBefore: 120,
        firstLineIndent: 720 // 0.5 inch indent
    } )
Option
Unit
Description

spacingBefore

twips

Space before paragraph (240 twips ≈ 12pt)

spacingAfter

twips

Space after paragraph

lineSpacing

twips

Line spacing (240 = single, 360 = 1.5, 480 = double)

firstLineIndent

twips

First line indentation (720 twips ≈ 0.5in)

Twips (twentieth of a point) is a standard unit in Word. Common values:

  • 240 twips = 12pt = single line spacing

  • 360 twips = 18pt = 1.5 line spacing

  • 480 twips = 24pt = double line spacing

  • 720 twips = 36pt = 0.5 inch indent


Run Formatting

Font Properties

Control per-character formatting within paragraphs:

Colors

Specify colors as hex values (with or without #):

Combined Formatting


Page Setup

Margins

Page Size

Orientation

Headers & Footers


Tables

Table headers (first row) are automatically bold:

For more advanced table formatting (cell borders, background colors, merging), use the underlying XWPFDocument via .getDocument(). Future versions will add native table styling.


Headings

Headings 1–2 are bold by default; headings 3–6 use the Word style's built-in formatting:

Heading levels are clamped to 1–6. Level 0 → 1; level 7+ → 6.


Hyperlinks are rendered as blue, underlined text:


Lists

Unordered (Bulleted)

Ordered (Numbered)

With Nested Sub-lists


Default Font

Apply a consistent font to all existing text runs:


Document Properties


User GuideAdvanced FeaturesExamples

Last updated

Was this helpful?