Expand description
rwml — one native Rust reader for both Microsoft Word formats: legacy
.doc (Word 97–2003 binary, [MS-DOC]) and modern .docx (OOXML
WordprocessingML). No JVM, no Apache POI, no external .docx crate, no
shelling out — Document::open format-detects from the magic bytes and
both feed the same DocModel and Markdown/HTML exporters.
.docis an OLE2/CFB compound file. The text lives in theWordDocumentstream; the piece table (CLX) in the0Table/1Tablestream maps character positions to byte offsets, and each piece is either UTF-16LE (Korean body text) or 8-bit text in the document’s ANSI codepage (fCompressed— cp1252 for Western, cp949 for Korean, from the FIB language id)..docxis a ZIP of XML parts (word/document.xml+ styles, numbering, relationships, media), parsed withzip+quick-xmlbehind the defaultdocxfeature. Disable it (default-features = false) for a dependency-light.doc-only build.
// Works for either format — detection is automatic.
let bytes = std::fs::read("report.doc").unwrap();
let text = rwml::extract_text(&bytes).unwrap();
println!("{text}");Two surfaces:
- Flat text —
extract_text/Document::text, the same output as POIWordExtractor.getText()(fast, allocation-light). - A full document model —
Document::model(paragraphs, character runs with bold/italic/…, structured tables with colspan/rowspan, headings, lists, hyperlinks, and extracted images), plusDocument::to_markdownandDocument::to_html. Built lazily, so the flat path never pays for it.
Parsing untrusted input is panic-free / bounds-checked: a malformed or hostile
.doc/.docx yields Error, never a crash. (The only expect is on the crate’s
own compiled-in blank template behind the infallible Document::new/Default;
use Document::try_new for a Result instead of that build-invariant panic.)
rwml (from WordprocessingML) is an independent project, not affiliated with or
endorsed by Microsoft. Microsoft Word and the .doc/.docx formats are Microsoft
trademarks, referenced only to indicate format compatibility; the crate is built
solely from the public [MS-DOC]/[MS-CFB]/OOXML specifications.
Modules§
- wasm
- Browser/WASM adapter functions over the same core
crate::DocumentAPI.
Structs§
- Authored
Comment - A comment to author on a generated run.
- Authored
Content Control - Plain text content-control metadata to author on a generated run.
- Authored
Note - Footnote or endnote metadata to author after a generated run.
- Authored
Revision - Tracked revision metadata to author on a generated run.
- Cell
- A table cell — may hold block content and span rows/columns.
- Cell
Builder - Thin builder for a table cell with block content and layout metadata.
- Cell
Margins - Table-cell margins in twips (1/20 point), ordered by physical side.
- Char
Props - Character-level formatting that affects rendering.
- Chart
- A block-level chart with literal category and numeric caches.
- Chart
Builder - Thin builder for a block-level
Chart. - Chart
Series - One named chart series with literal numeric values.
- Color
- An sRGB color.
- Comment
- A Word comment extracted from a
.docxcomments part or recovered from a legacy.docannotation subdocument. - Comment
Builder - Thin builder for a generated Word comment body and metadata.
- Content
Control Builder - Thin builder for generated plain text content-control metadata.
- Core
Properties - Core document properties extracted from
docProps/core.xmlor generated document setup metadata. - DocBuilder
- Thin builder for creating a
DocModelwithout filling every struct field by hand. - DocGrid
- Document grid settings for a WordprocessingML section.
- DocMeta
- Document-level metadata.
- DocModel
- A whole
.docdocument as an ordered list of block-level nodes plus document-level metadata. - DocSetup
- Document-level layout + metadata, for authoring and rendering. All fields are optional/default so existing read paths are unaffected.
- Document
- A parsed Word document — either legacy
.doc(OLE2/[MS-DOC]) or modern.docx(OOXML).Document::openformat-detects from the magic bytes and both backends feed the sameDocModeland exporters, sotext(),to_markdown(),to_html(), andimages()behave identically regardless of which Word format the bytes are in. - Document
Report - Summary of the opened document’s format, visible stats, observed feature markers, and warnings.
- Edit
Capability - Whether package-preserving edit APIs are available for an opened document.
- Feature
Inventory - Counts of Word features observed while opening a document.
- Field
- A Word field observed in a
.docxbody. - Field
Context - Caller-supplied evaluation context for volatile or external-data fields.
- Field
Evaluation Reason Count - Count of unsupported field evaluations for one reason.
- Field
Kind Count - Count of observed fields for one field kind.
- Floating
Shape - Floating shape geometry recovered from a Word document.
- Header
Footer - A running header/footer record recovered from a Word document.
- Image
- An embedded image.
bytes/mimeare present only when the picture was extracted; otherwise the node is a placeholder. - Image
Builder - Thin builder for an embedded
Imageblock. - Indent
- Paragraph indentation in points;
None= unset. - List
Info - List membership of a paragraph.
- Metafile
Info - Best-effort metadata for a preserved WMF/EMF package part.
- Note
- A footnote or endnote recovered from a Word document.
- Page
Setup - Page geometry, in points. Default is A4 portrait with 1-inch margins.
- Para
Props - Paragraph-level properties.
- Paragraph
- A paragraph: inline runs plus paragraph-level properties.
- Paragraph
Builder - Thin builder for a paragraph with runs and paragraph-level layout.
- Paragraph
Style - A paragraph style definition for generated
.docxoutput. - Paragraph
Style Builder - Thin builder for a paragraph style definition.
- Render
Report - Renderer metrics and warnings for a generated PDF.
- Rendered
Pdf - PDF bytes plus the render report produced by the same pagination pass.
- Revision
- A tracked revision extracted from a
.docxbody. - Revision
Builder - Thin builder for generated tracked insertion/deletion metadata.
- Row
- A table row.
- Run
- An inline run of text with uniform character properties.
- RunBuilder
- Thin builder for an inline
Runwith character formatting. - Section
Setup - Section-level layout recovered from or generated into
.docxsection properties. - Shape
Distance - Distance from a floating shape to surrounding text, in English Metric Units.
- Shape
Effect Extent - Visual-effect extents for a recovered floating shape, in English Metric Units.
- Shape
Extent - Drawing extent for a recovered floating shape, in English Metric Units.
- Shape
Point - Absolute point for a recovered floating shape, in English Metric Units.
- Shape
Position - Positioning metadata for a recovered floating shape.
- Shape
Wrapping - Text-wrapping policy declared by a floating shape anchor.
- Source
Region - A span of
DocModel::blocksthat came from one source subdocument. - Spacing
- Paragraph spacing in points;
None= unset (renderer/writer uses defaults). - Stats
- Aggregate document statistics, mirroring the project-wide
DocStatscontract. - Table
- A table: rows of cells.
- Table
Border Colors - Optional table border colors by physical side.
- Table
Border Sizes - Optional table border widths by physical side, in eighths of a point.
- Table
Border Styles - Optional table border line styles by physical side.
- Table
Builder - Thin builder for rich
Tablevalues. - Text
Anchor - A text range in the main document body associated with an annotation.
- TextBox
- A text box recovered from a Word document.
- WebExtension
Task Pane - A generated Office web-extension task pane package entry.
Enums§
- Align
- Paragraph alignment.
- Block
- A block-level node.
- Chart
Kind - Supported chart layouts for authored
.docxoutput. - Chart
Shape - Supported shape styles for authored 3-D bar/column charts.
- Core
Property - Editable
.docxcore document properties supported byDocument::set_core_property. - DocGrid
Type - Document grid behavior for a WordprocessingML section.
- Document
Format - Source document format detected by
crate::Document::open. - Document
Warning - Human- and machine-readable warnings derived from
FeatureInventory. - Edit
Read Only Reason - Reason package-preserving edits are unavailable for an opened document.
- Error
- Errors produced while opening or decoding a
.docfile. - Field
Evaluation Reason - Reason a field’s computed value is not available.
- Field
Kind - Known Word field instruction classes rwml distinguishes.
- Field
Role - Whether a run is plain text or the cached result of a field.
- Field
Unsupported Reason - Best-effort reason an imported field remains cached in the model.
- Header
Footer Kind - Kind of running header/footer region recovered from a Word document.
- Metafile
Format - Metafile image container observed in a package.
- Note
Kind - Kind of note recovered from a Word document.
- Page
Number Format - Display format for generated section page numbers.
- Render
Warning - Human- and machine-readable warnings derived from features the current renderer cannot faithfully compute or draw yet.
- Revision
Kind - Kind of tracked revision marker observed in a
.docxbody. - Revision
View - Flat text view policy for tracked revisions.
- Section
Break Kind - Section-break start behavior for a WordprocessingML section boundary.
- Source
Region Kind - A coarse source subdocument region from the original Word file.
- Table
Border Side - A physical side of a table border.
- Table
Border Style - Uniform table border line style.
- Text
Direction - Text flow direction for generated
.docxsection properties. - VCell
- Vertical alignment of cell content.
- Vert
Align - Vertical alignment of a run (super/subscript).
Functions§
- extract_
text - Convenience: decode
.docbytes into normalized plain text (all sub-documents — main body, then footnotes/endnotes/headers). Errors withError::NoTextif nothing indexable was found. - try_
write_ docx - Fallible variant of
write_docx: returns the serialization error instead of an empty buffer if packaging ever fails. Prefer this when you need to surface write failures rather than silently emit nothing. - write_
docx - Serialize a
DocModel— one you built from data, built withDocBuilder, or read from a.doc/.docx— to a clean, Office-openable.docxbyte buffer. This is the authoring entry point: construct a model (paragraphs/runs with fonts, sizes, colors; headings; styled/sized/shaded tables; images; page setup) and write a styled Word document. Available with the defaultdocxfeature.
Type Aliases§
- Result
- Convenience alias.