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

Import & Export

Import and export Word documents to and from text, Markdown, and HTML formats

Convert Word documents to and from text, Markdown, and HTML formats.


Importing Content

From Plain Text

Split paragraphs on double newlines:

text = "Line one\n\nLine two\n\nLine three"

// Via BIF argument
word( text=text ).save( "from-text.docx" )

// Via instance method (appends to existing document)
word( "template.docx" )
    .fromText( text )
    .save( "appended.docx" )

From Markdown

Uses CommonMark parsing β€” supports headings, paragraphs, lists, code blocks, blockquotes, links, and thematic breaks:

markdown = "
## Introduction

This is a paragraph with **bold** and *italic* text.

- Item 1
- Item 2
- Item 3

> A blockquote

`inline code`
"

// Via BIF argument
word( markdown=markdown ).save( "from-markdown.docx" )

// Via instance method
word().fromMarkdown( markdown ).save( "from-markdown.docx" )

From HTML

Uses Jsoup parsing β€” supports headings, paragraphs, lists, tables, images, links, and basic formatting:

Supported HTML Elements

HTML Element
Word Output

<h1>–<h6>

Heading (level 1–6)

<p>

Paragraph

<br>

New line

<b>, <strong>

Bold text

<i>, <em>

Italic text

<ul>

Unordered (bulleted) list

<ol>

Ordered (numbered) list

<li>

List item (supports nesting)

<table>, <tr>, <td>, <th>

Table

<a href="...">

Hyperlink

<img src="...">

Image (base64 data URIs supported)

<pre>, <code>

Monospace paragraph

<blockquote>

Indented, italic paragraph

<hr>

Page break


Exporting Content

To Plain Text

Extracts all visible text including tables (tab-separated), headers, and footers:

Output example:

Table cells are separated by tabs (\t). Headers and footers are prefixed with [Header] and [Footer] markers.

To Markdown

Converts to Markdown with:

  • YAML front matter (title, author, subject from document properties)

  • # headings with proper level

  • Pipe-delimited tables

  • **bold** / *italic* formatting

  • Base64-embedded images

  • Blockquoted headers and footers

Output example:

To HTML

Converts to a full HTML document with:

  • Semantic heading tags (<h1>–<h6>)

  • Standard <table> structure with <thead>/<tbody>

  • Inline styles for bold, italic, color, size, and font family

  • Base64-embedded images

  • <footer> elements for headers and footers

Output example:


Format Conversion Pipeline

Chain import and export for format conversion:


Fidelity Notes

Direction
Preserved
Lost

Word β†’ Text

Visible text, table structure

All formatting, images, headers

Word β†’ Markdown

Headings, tables, bold/italic, images (base64)

Exact font/size/color, custom styles

Word β†’ HTML

Headings, tables, bold/italic, colors, fonts, images (base64)

Custom paragraph spacing, section breaks

Markdown β†’ Word

Headings, paragraphs, lists, bold/italic, code, links, blockquotes

Embedded images become links

HTML β†’ Word

Headings, paragraphs, lists, tables, bold, links, base64 images

CSS classes, external stylesheets

Text β†’ Word

Paragraph structure (double-newline split)

All formatting


User GuideFormattingFluent API

Last updated

Was this helpful?