Word Document to plain text

Convert a Microsoft Word document to plain text in the browser.

Face with waiting expression Nothing to see yet!

Loading takeymakey...
TakeyMakey code
Want this tool to do something else? Edit the code below and make it do whatever you want.
import mammoth from "https://cdn.jsdelivr.net/npm/mammoth@1.9.0/+esm"

export const take = [
  {
    type: "file",
    label: "Document",
    accept: ".doc,.docx,application/msword",
    read: "buffer",
  },
  { type: "toggle", label: "Remove excess new lines", value: true },
]

export const make = async ([arrayBuffer, stripnl]) => {
  let value

  if (arrayBuffer) {
    value = (await mammoth.extractRawText({ arrayBuffer })).value

    if (stripnl) {
      value = value
        .replace(/\n +/g, "\n")
        .replace(/\n\n\s*/g, "\n\n")
        .trim()
    }

    return [{ type: "text", value }]
  }
}