> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-+-++/modules/bx-word/quick-start.md).

# Quick Start

Create your first Word document with BoxLang in under 5 minutes

Get up and running with the BoxLang Word Module in minutes.

***

## 📦 Installation

Install the module via CommandBox:

```bash
box install bx-word
```

>

> This module requires a **BoxLang+ license**. Make sure `bx-plus` is installed and licensed.

***

## 1. Your First Document

Create a new document, add content, and save it — all in a single fluent chain:

```js
word( "my-first-document.docx" )
    .addHeading( "Hello, BoxLang!", 1 )
    .addParagraph( "This is my first Word document created with BoxLang." )
    .save()
```

That's it! You now have a `.docx` file on disk.

***

## 2. Adding Content

### Headings

Add headings at levels 1 through 6:

```js
word()
    .addHeading( "Main Title", 1 )
    .addHeading( "Section", 2 )
    .addHeading( "Sub-section", 3 )
    .save( "headings.docx" )
```

### Paragraphs

Plain and formatted paragraphs:

```js
word()
    .addParagraph( "A simple paragraph." )
    .addParagraph( "Bold and colored text.", { bold: true, color: "FF0000", size: 14 } )
    .save( "paragraphs.docx" )
```

### Tables

Tables from arrays, queries, or structs:

```js
word()
    .addHeading( "Team Roster", 2 )
    .addTable( [
        [ "Name", "Role", "Location" ],
        [ "Alice", "Engineer", "New York" ],
        [ "Bob", "Designer", "London" ]
    ] )
    .save( "table.docx" )
```

{% hint style="success" %}
The first row is automatically bolded as the header row.
{% endhint %}

### Lists

Ordered and unordered lists:

```js
word()
    .addHeading( "Agenda", 2 )
    .addOrderedList( [ "Introductions", "Quarterly Review", "Q&A" ] )
    .addUnorderedList( [ "Apples", "Bananas", "Cherries" ] )
    .save( "lists.docx" )
```

### Images

Images from files, bytes, base64, or URLs:

```js
word()
    .addHeading( "Photo", 2 )
    .addImage( "/path/to/photo.png" )           // from file (10cm × 7.5cm default)
    .addImage( "/path/to/logo.png", 5.0, 3.0 )  // with explicit dimensions
    .addImageFromUrl( "https://example.com/pic.jpg" )
    .save( "images.docx" )
```

### Hyperlinks

Clickable links:

```js
word()
    .addHyperlink( "Visit BoxLang", "https://boxlang.io" )
    .save( "links.docx" )
```

***

## 3. Opening Existing Documents

Load an existing `.docx` file to modify it:

```js
word( "/path/to/existing.docx" )
    .addParagraph( "Appended content!" )
    .save( "/path/to/modified.docx" )
```

***

## 4. Template Population

Replace `{{placeholders}}` in a template with real data:

```js
word( "/templates/contract.docx" )
    .populate( {
        clientName: "Acme Corp",
        signDate: "2024-06-15",
        contractValue: "$50,000"
    } )
    .save( "/output/contract_acme.docx" )
```

***

## 5. Exporting to Other Formats

Convert your document to text, Markdown, or HTML:

```js
doc = word()
    .addHeading( "Report", 1 )
    .addParagraph( "Q4 results are in." )
    .addTable( [ [ "Metric", "Value" ], [ "Revenue", "$1.2M" ] ] )

// Export to different formats
plainText = doc.toText()
markdown  = doc.toMarkdown()
html      = doc.toHTML()

// Or save as .docx
doc.save( "report.docx" )
```

| Method          | Output                                                      |
| --------------- | ----------------------------------------------------------- |
| `.toText()`     | Plain text with tab-separated tables                        |
| `.toMarkdown()` | Markdown with YAML front matter, pipe tables, base64 images |
| `.toHTML()`     | HTML with inline styles and base64 images                   |

***

## 6. Page Setup

Control margins, size, orientation, headers, and footers:

```js
word()
    .margins( 1.5, 1.5, 2.0, 2.0 )   // top, bottom, left, right in cm
    .pageSize( "A4" )                   // A4, LETTER, LEGAL
    .orientation( "landscape" )         // portrait or landscape
    .header( "Company Confidential" )
    .footer( "Page 1" )
    .addParagraph( "Content goes here..." )
    .save( "formatted.docx" )
```

***

## 7. Document Properties

* Dive into the [User Guide](/boxlang-+-++/modules/bx-word/user-guide.md) for comprehensive coverage
* Explore [Formatting](/boxlang-+-++/modules/bx-word/formatting.md) options for paragraphs and runs
* Learn about [Import & Export](/boxlang-+-++/modules/bx-word/import-export.md) conversion pipelines
* Check out [Advanced Features](/boxlang-+-++/modules/bx-word/advanced-features.md) for watermarks, TOC, and protection
* Browse [Examples](/boxlang-+-++/modules/bx-word/examples.md) for real-world patterns


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-+-++/modules/bx-word/quick-start.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
