Install
Add the package with a single command:
dart pub add docx_to_markdown
# Flutter:
flutter pub add docx_to_markdown Convert a document
The converter works on bytes, so load the file however you like. It never touches the disk or network unless you ask it to.
import 'dart:io';
import 'package:docx_to_markdown/docx_to_markdown.dart';
Future<void> main() async {
final bytes = await File('document.docx').readAsBytes();
// Defaults: GitHub Flavored Markdown, footnotes on, tables auto.
final markdown = await DocxConverter(bytes).convert();
print(markdown);
} Tune the output
Pass a DocxToMarkdownConfig. Every option has a sensible
default, so override only what you need - flavor, tables, image
sizing, metadata, tracked changes and more.
final config = DocxToMarkdownConfig(
flavor: MarkdownFlavor.commonmark,
tableMode: TableMode.auto,
imageSizeMode: ImageSizeMode.obsidian, // 
metadataMode: MetadataMode.yamlFrontMatter, // prepend YAML front matter
);
final markdown = await DocxConverter(bytes, config: config).convert(); On the web
There is no filesystem in the browser, so images flow through an
imageAssetSink you control - exactly how this website
exports them. (It is the same code path running right now.)
// On the web there is no filesystem, so route image bytes to a sink.
final images = <DocxImageAsset>[];
final markdown = await DocxConverter(bytes).convert(
imageAssetSink: (asset) {
images.add(asset); // keep the bytes...
return 'images/${asset.suggestedFilename}'; // ...and reference them here
},
); Extend it with hooks
Rewrite links and image targets, transform or drop blocks and inlines, convert equations to LaTeX, or collect warnings - all without forking.
final hooks = DocxToMarkdownHooks(
rewriteImageTarget: (src, [ctx]) => 'https://cdn.example.com/$src',
transformBlock: (block, ctx) => block is TableBlock ? null : block, // drop tables
onWarning: (w, ctx) => print('[${w.code}] ${w.message}'),
);
final md = await DocxConverter(
bytes,
config: DocxToMarkdownConfig(hooks: hooks),
).convert();