DOCXLibWord documents for Ring

Document setup and text

Metadata, page size, columns, themes, styles, headers and footers, paragraphs, rich text and lists.

Document Setup#

Setup methods configure global document properties and should be called before adding content.

Document Metadata#

MethodParametersDescription
setTitle()title : StringSets the document title (written to core.xml)
setAuthor()author : StringSets the document author (written to core.xml)
setDefaultFont()fontName, fontSizeBody font and size in pt. Defaults: Calibri, 11pt
addCustomProperty()name, valueAdd a custom document property (written to custom.xml)

Page Size and Orientation#

MethodParametersDescription
setPageSize()size : String"letter", "a4", "legal", "a3", "b5". Default: letter
setCustomPageSize()widthCm, heightCmExact page dimensions in centimetres
setOrientation()orientation"portrait" or "landscape"
setMargins()top, bottom, left, rightPage margins in centimetres
setMarginsInches()top, bottom, left, rightPage margins in inches
setNarrowMargins()—0.5" margins on all four sides
setWideMargins()—1.5" margins on all four sides
Ring
doc.setPageSize("a4")
doc.setMargins(2.54, 2.54, 2.54, 2.54)   # 1 inch all sides

Multi-Column Layouts#

MethodParametersDescription
setColumns()numColumns, spaceCmSet column count and gap in cm
setTwoColumns()—Two equal columns, 0.5 cm gap
setThreeColumns()—Three equal columns, 0.5 cm gap
addColumnBreak()—Insert a column break at the current position
addSectionBreak()breakType, optionsInsert a section break with optional layout
addLandscapeStart()—Begin a landscape section
addLandscapeEnd()—End the landscape section

addSectionBreak() break types: "continuous", "nextPage", "evenPage", "oddPage". The second argument is an options list — pass [] when no options are needed:

OptionTypeDescription
:numColumnsNumberColumn count for the new section (2 or more enables multi-column)
:columnSpaceCmNumberGap between columns in cm
Ring
# Two-column newsletter — begin on same page
doc.addSectionBreak("continuous", [:numColumns=2, :columnSpaceCm=0.6])
doc.addParagraph("Left column content...", [])
doc.addColumnBreak()
doc.addParagraph("Right column content...", [])

# Return to single-column on the next page
doc.addSectionBreak("nextPage", [])

# Landscape page within a portrait document
doc.addLandscapeStart()
doc.addTable(wideData, options)
doc.addLandscapeEnd()

Document Themes#

setTheme() applies a colour palette to all heading levels and writes word/theme/theme1.xml. Call it before save().

Ring
doc.setTheme("Blue")
ThemeAccent 1 (H1/H2)Accent 2 (H3/H4)
Office#4472C4 Blue#ED7D31 Orange
Blue#1E6BB5 Deep Blue#2E75B6 Mid Blue
Dark#88C0D0 Ice Blue#81A1C1 Steel Blue
Green#375623 Forest#70AD47 Lime
Red#C00000 Dark Red#FF0000 Red
Purple#7030A0 Purple#9B59B6 Violet
Teal#00796B Teal#009688 Medium Teal
Warm#E65100 Deep Orange#F57C00 Orange

Custom Paragraph Styles#

defineStyle() registers a named paragraph style. Use the style name via :style in addParagraph().

Ring
doc.defineStyle("CalloutBox", [
    :basedOn     = "Normal",
    :bold        = true,
    :size        = 11,
    :color       = "1E6BB5",
    :bgColor     = "DEEAF1",
    :align       = "center",
    :spaceBefore = 120,
    :spaceAfter  = 120
])

doc.addParagraph("This uses the custom style.", [:style = "CalloutBox"])
defineStyle optionTypeDescription
:basedOnStringParent style ID, e.g. "Normal", "Heading1"
:boldtrue/falseBold text
:italictrue/falseItalic text
:underlinetrue/falseUnderlined text
:fontStringFont family name
:sizeNumberFont size in points
:colorStringText colour hex without #
:alignString"left", "center", "right", "both"
:bgColorStringParagraph background fill colour hex
:spaceBeforeNumberSpace before in twips (20 twips = 1 pt)
:spaceAfterNumberSpace after in twips
:lineSpacingNumberLine spacing multiplier: 1.5, 2.0, etc.
:indentNumberLeft indent in twips
:keepNexttrue/falseKeep with the next paragraph
:keepLinestrue/falsePrevent splitting across pages

Headers, Footers, and Page Numbers#

MethodParametersDescription
setHeader()textDefault header text (centred)
setFooter()textDefault footer text
setHeaderFooter()headerText, footerTextSet both in one call
showPageNumbers()alignAdd page numbers: "left", "center", "right"
setFirstPageDifferent()bEnableEnable a different header/footer on page 1
setFirstPageHeader()textHeader text for the first page only
setFirstPageFooter()textFooter text for the first page only
setEvenAndOddHeaders()bEnableEnable separate headers for even/odd pages
setEvenPageHeader()textHeader text for even-numbered (left) pages
setEvenPageFooter()textFooter text for even-numbered pages
Ring
# Standard header with page numbers
doc.setHeader("Annual Report 2026")
doc.showPageNumbers("right")

# Cover page — no header, subsequent pages with header
doc.setFirstPageDifferent(true)
doc.setFirstPageHeader("")          # blank on cover
doc.setHeader("Chapter 1 — Introduction")

# Book-style even/odd headers
doc.setEvenAndOddHeaders(true)
doc.setHeader("Ring Language Study")           # odd pages (right side)
doc.setEvenPageHeader("Mahmoud, 2026")   # even pages (left side)

Text and Paragraphs#

addParagraph()#

The primary content method. Pass [] or NULL as the second argument to use all defaults.

Ring
doc.addParagraph("Plain text paragraph.", [])
doc.addParagraph("Bold red heading", [:bold=true, :color="C00000", :size=14])
doc.addParagraph("Centred note",     [:align="center", :italic=true])
doc.addParagraph("Custom style",     [:style="CalloutBox"])
OptionTypeDescription
:boldtrue/falseBold text
:italictrue/falseItalic text
:underlinetrue/falseUnderlined text
:sizeNumberFont size in points
:fontStringFont family name
:colorStringText colour hex, e.g. "C00000"
:charStyleStringNamed character style, e.g. "Strong", "Emphasis"
:langStringBCP 47 language tag, e.g. "ar-SA", "fr-FR", "de-DE"
:alignString"left", "center", "right", "both"
:styleStringNamed paragraph style
:bgColorStringParagraph background colour hex
:spaceBeforeNumberSpace before in twips (20 twips = 1 pt)
:spaceAfterNumberSpace after in twips
:lineSpacingNumberLine spacing multiplier, e.g. 1.5
:indentNumberLeft indent in twips
:keepNexttrue/falseKeep this paragraph on the same page as the next
:keepLinestrue/falsePrevent the paragraph from splitting across pages
:suppressLineNumberstrue/falseExclude from line numbering
:contextualSpacingtrue/falseSuppress spacing between same-style paragraphs
:widowControlfalseSet false to disable widow/orphan protection (Word default is on)
:noHyphenatetrueSuppress automatic hyphenation on this paragraph

Headings and Titles#

Ring
doc.addHeading("Chapter 1 — Introduction", 1)   # Heading 1
doc.addHeading("1.1 Background", 2)              # Heading 2
doc.addHeading("Sub-section detail", 3)          # Heading 3  (levels 1–6)
doc.addTitle("Document Title")                   # Title style
doc.addSubtitle("A subtitle line")               # Subtitle style

addRichParagraph() — Mixed Formatting#

Build a paragraph from an explicit list of [text, options] run pairs. Each run can carry its own bold, italic, colour, size, font, language, and character style.

Ring
doc.addRichParagraph([
    ["Status: ",  []],
    ["Passed",    [:bold=true, :color="375623"]],
    ["  —  Score: ", []],
    ["98/100",    [:bold=true, :color="1E6BB5", :size=14]]
], [:align="center"])

# Language-tagged runs (Arabic + English in one paragraph)
doc.addRichParagraph([
    ["مرحبا",    [:font="Arial", :lang="ar-SA"]],
    [" — Hello", [:lang="en-US"]]
], [])

# Character styles
doc.addRichParagraph([
    ["See ",         []],
    ["ring-lang.github.io", [:charStyle="Hyperlink"]]
], [])

Run-level option keys: :text, :bold, :italic, :underline, :color, :size, :font, :bgColor, :charStyle, :lang.

Shorthand Methods#

MethodDescription
bold(text)Bold paragraph
italic(text)Italic paragraph
underline(text)Underlined paragraph
colored(text, color)Coloured text (hex colour)
styled(text, font, size, color)Single-call full style
centered(text)Centre-aligned paragraph
rightAligned(text)Right-aligned paragraph
justified(text)Justified paragraph
addBlockQuote(text)Indented block-quote paragraph
addCaption(text)Small centred italic caption
addAbstract(text)Indented abstract block with bold "Abstract" heading
addKeywords(text)Keywords line with bold "Keywords:" prefix
addEmptyParagraph()One blank line
addHorizontalLine()Full-width horizontal rule
addPageBreak()Hard page break
addLineBreak()Soft line break within a paragraph

Shaded and Bordered Paragraphs#

Ring
# Solid background colour
doc.addShadedParagraph("Important note", "FFF3CD", [:bold=true])

# Full border box with optional background
doc.addBorderedParagraph("Critical warning", [
    :borderStyle = "single",
    :borderColor = "C00000",
    :bgColor     = "FDECEA",
    :spaceBefore = 80,
    :spaceAfter  = 80,
    :indent      = 240
])

Widow/Orphan Control and Auto-Hyphenation#

Word protects against widows (last line stranded on the next page) and orphans (first line stranded at the bottom) by default. You can also suppress automatic hyphenation per paragraph — useful for technical terms, URLs, and headings.

Ring
# Disable widow/orphan protection for a data-dense paragraph
doc.addParagraph(denseText, [:align="both", :widowControl=false])

# Suppress auto-hyphenation (useful for URLs, product codes, headings)
doc.addParagraph(longTechnicalTerm, [:noHyphenate=true])

# Both together — dense justified paragraph that must not be hyphenated
doc.addParagraph(body, [:align="both", :widowControl=false, :noHyphenate=true])

Lists#

DOCXLib generates proper Word OOXML list numbering — not manually inserted bullet characters.

Ring
# Simple bullet list
doc.addBulletList(["Ring language", "Python", "JavaScript"])

# Numbered list
doc.addNumberedList(["Install Ring", "Load docxlib.ring", "Call save()"])

# Nested bullet list — inner list items are sub-lists
doc.addNestedBulletList([
    "Programming Languages",
    ["Ring", "Python", "Java"],
    "Databases",
    ["SQLite", "MySQL"]
])

# Nested numbered list
doc.addNestedNumberedList([
    "Phase 1 — Design",
    ["Requirements", "Architecture"],
    "Phase 2 — Development"
])
DOCXLib - Word documents for Ring, made with ringdoc.