Convert DOCX to Markdown in C#

DocxToMarkdownConverter turns a Word document into Markdown: a heading becomes #, a table becomes a pipe table. Images are embedded as data: URIs, so the Markdown stands on its own.

using DocToolkit;

byte[] docx = File.ReadAllBytes("input.docx");
string markdown = DocxToMarkdownConverter.Convert(docx);
File.WriteAllText("output.md", markdown);

What it needs

  • No browser, headless or otherwise.
  • No Office install, and no LibreOffice.
  • No native files: managed code only.
  • No network at runtime, unless you ask for it.

Good to know

  • Synchronous: Convert takes the .docx as a byte[] and returns the Markdown as a string.
  • This is the lossier direction by a wide margin: Word expresses far more than Markdown can.
  • ConvertWithReport returns the same Markdown and a list of what was lost. An empty list means nothing was lost that the converter knows about.
  • Images are embedded as data: URIs, not written to files beside the output.

Install

dotnet add package Ank.DocToolkit

NuGetDocumentationGitHub