Skip to main content

index

CI crates.io docs.rs License: MIT/Apache-2.0 MSRV: 1.93

rdocx gives Rust applications one Document for the complete Word workflow. Create a business document, open and edit a customer template, retain producer content you do not model, lay out the result, and deliver DOCX, PDF, page images, HTML, or Markdown without starting Microsoft Word or LibreOffice.

This is an integrated native document stack, not only a DOCX writer. The same engine powers Rust, the command line, Python, and a locally built browser package. Project-owned layout and bundled fonts make deterministic output possible without an Office installation or conversion service.

Built for complete document workflows​

WorkflowImplemented result
DOCXCreate, open, edit, validate, and save complete packages, with encryption and signing through opt-in features
Rich authoringParagraphs, runs, tables, styles, numbering, fields, forms, equations, drawings, comments, and metadata
PreservationRetain unknown safe producer XML byte for byte when it is not modelled
Native layoutResolve Word flow content into positioned pages with bundled, system, embedded, or caller-provided fonts
Fixed outputPDF, PDF/A, PNG, JPEG, TIFF, and SVG
Flow outputHTML, HTML fragments, Markdown, MHTML, RTF, ODT, and EPUB
AutomationRust facade, CLI, Python binding, and locally built browser binding

Most applications need only rdocx. Specialist crates expose the OPC, WordprocessingML, layout, HTML, and fixed-output layers for applications that already own one of those boundaries.

Examples​

Create a document​

use rdocx::{Document, Length};

let mut document = Document::new();
document.add_paragraph("Quarterly report");

let mut summary = document.add_paragraph("");
summary.add_run("Status: ").bold(true);
summary.add_run("approved");

let mut table = document.add_table(1, 2);
assert!(table.set_column_width(0, Length::inches(2.0)));
assert!(table.set_column_width(1, Length::inches(4.0)));

document.save("report.docx")?;
# Ok::<(), rdocx::Error>(())

Read and update a document​

use rdocx::Document;
use std::collections::HashMap;

let mut document = Document::open("template.docx")?;
for paragraph in document.paragraphs() {
println!("{}", paragraph.text());
}

let mut replacements = HashMap::new();
replacements.insert("{{status}}", "Approved");
document.replace_all(&replacements);
document.save("approved.docx")?;
# Ok::<(), rdocx::Error>(())

Render and export​

use rdocx::Document;

let document = Document::open("report.docx")?;
document.save_pdf("report.pdf")?;
let first_page_png = document.render_page_to_png_deterministic(0, 150.0)?;
let html = document.to_html();
let markdown = document.to_markdown();

assert!(first_page_png.as_ref().is_some_and(|png| !png.is_empty()));
assert!(!html.is_empty());
assert!(!markdown.is_empty());
# Ok::<(), rdocx::Error>(())

Installation​

Most Rust applications need only the facade:

[dependencies]
rdocx = "0.13.1"

Bundled metric-compatible fonts are always available through deterministic rendering. The default feature also discovers system fonts. Disable default features when an application must use only the bundled set:

[dependencies]
rdocx = { version = "0.13.1", default-features = false }

Native encryption and signing APIs are opt-in:

[dependencies]
rdocx = { version = "0.13.1", features = ["agile-encryption", "digital-signatures"] }

The workspace requires Rust 1.93 or newer and uses edition 2024.

CLI​

Install the CLI version from the same stable family:

cargo install rdocx-cli --version '^0.13.1'

Common commands:

rdocx inspect report.docx
rdocx text report.docx
rdocx convert report.docx --to pdf -o report.pdf
rdocx convert report.docx --to html -o report.html
rdocx convert report.docx --to md -o report.md
rdocx replace report.docx --placeholder "Draft" --value "Final" -o final.docx
rdocx diff before.docx after.docx

Surfaces​

SurfaceBoundary
rdocxNative Rust facade for complete DOCX packages, authoring, conversion, and rendering
rdocx-oxmlTyped WordprocessingML for callers that already own the lower-level model
rdocx-layoutWord flow layout for callers that already own layout input
rdocx-htmlHTML and Markdown export from parsed Word content
rdocx-cliShell automation for inspection, conversion, validation, rendering, replacement, and diffing
rdocx-pyPython editing, DOCX save, PDF output, and page images
rdocx-wasmBrowser and JavaScript round trips with PDF, HTML, and Markdown export

The binding specification defines where Python, WebAssembly, and CLI intentionally expose less than native Rust.

Evidence-based alternatives​

Comparison checked 2026-09-09. ND means the capability was not documented in the official sources linked below. It does not mean the capability is impossible. Native layout means a page-layout engine implemented by the library, rather than conversion through Microsoft Office, a hosted service, or another renderer.

ProjectDOCX open, create, editPreservationNative layout and renderPDF and rasterHTML and MarkdownCLIPythonBrowser and WASM
rdocxOpen, create, edit, and saveUnknown safe producer XML is retained byte for byte when it is not modelledYes, Word flow layout with deterministic bundled fontsPDF and page imagesHTML and Markdown exportrdocx-clirdocx-py, with a narrower facadeWorkspace rdocx-wasm facade, deliberately unpublished
python-docxCreate, open, change, and saveExisting content that its API cannot manipulate is left alone on load and save. No byte-exact guarantee is statedNDNDNDNDPrimary APIND
docx-rsCreate and parse into the model used by its writer. Editing a parsed document is not separately documentedND. The project states that its OOXML support is not exhaustiveNDNDNDNDNDDocument generation and DOCX-to-JSON parsing through WebAssembly
docx4jOpen, create, edit, and saveND for unknown XML or byte-exact round tripsNo project-owned page engine is documented. PDF paths use XSL-FO with Apache FOP, Microsoft Word through documents4j, or Microsoft GraphPDF through the documented conversion paths. Raster output is NDHTML export and first-party Markdown import and exportNDNDND
Aspose.WordsCreate, load, modify, and save DOCXFeature-level preservation is documented during conversion. No byte-exact unknown-XML contract is statedYes, its own page-layout enginePDF plus PNG, JPEG, BMP, and TIFFHTML and MarkdownNDOfficial Python via .NET APIND

Among these reviewed projects, rdocx alone documents the complete combination of a native Rust API, project-owned Word layout, fixed and flow outputs, a CLI, Python, and a browser surface. That statement is bounded to the official evidence set and review date. See the official python-docx document guide, docx-rs project, docx4j PDF paths, docx4j Markdown module, Aspose fixed-page documentation, Aspose format table, and Aspose load behavior.

Honest boundaries​

rdocx preserves safe unmodeled XML, but it does not execute VBA, ActiveX, OLE, add-ins, or embedded applications. Binary DOC and Word 2003 XML are permanent non-goals. Exact authoring, reading, rendering, and preservation coverage lives in the modern DOCX capability matrix.

License​

Licensed under either of:

at your option.