Command line
word2html [-h] [--version] [--strict] [--timeout SECONDS]
[--max-memory SIZE] [--max-file-size SIZE] path
Options
| Option | Default | What it does |
|---|---|---|
path | Required | The .docx file to convert. The extension isn't case-sensitive. |
--strict | Off | Refuse documents with unsafe links or hidden text instead of warning. See Security. |
--timeout SECONDS | 120 | Stop pandoc after this long. Decimals are allowed. |
--max-memory SIZE | 2G | Memory limit for pandoc. The minimum is 16M. |
--max-file-size SIZE | 200M | The largest input file to accept. |
--version | Show the version and exit. | |
-h, --help | Show help and exit. |
SIZE is a whole number with an optional unit: K, M, or G, such as 512M or 2G. A number alone means bytes. Units are powers of 1024, and 512MB and 512MiB both mean the same as 512M.
Exit codes
| Code | Meaning | Output file |
|---|---|---|
0 | Converted. Any warnings were printed to stderr. | Written |
1 | Invalid input, a limit was exceeded, or pandoc or the file write failed. | Not changed |
2 | Bad command line. | Not changed |
3 | Refused for safety. | Not changed |
The output file
- Location: next to the input, with the same name and an
.htmlextension.docs/Report.v2.DOCXbecomesdocs/Report.v2.html. - Overwriting: an existing file with that name is replaced without asking, keeping its permissions.
- Atomic: the new file is written separately and then swapped into place. If conversion fails or is refused, an existing file stays exactly as it was.
- Symlinks: if the output path is a symlink, the link itself is replaced and its target isn't touched.
- Page title: the text of a paragraph in Word's Title style if there is one, and otherwise the filename.
The success message goes to stdout. Warnings and errors go to stderr, so you can separate them in scripts.
What's kept and what isn't
| In the Word document | In the HTML |
|---|---|
| Text, headings, lists, tables, links, footnotes, highlights | Kept |
| Embedded images, PDFs, video, audio | Embedded in the HTML, so output can be larger than the .docx |
| Linked images, stored outside the document | Dropped with a warning, and never fetched |
| Tracked insertions | Published as if accepted |
| Tracked deletions | Dropped |
| Comments | Dropped |
| Paragraphs in Word's Title, Author, and Date styles | Kept, and also used for the page's metadata |
| Document properties, set in File › Info | Not published |
| Hidden text | Published as visible text, with a warning. See Security. |
Styling comes from pandoc's default CSS rather than the Word document, so fonts, colours, and page layout won't match the original.
Recipes
Convert a folder of documents
Use --strict and track failures, so one bad document doesn't go unnoticed:
status=0
for doc in ./*.docx; do
word2html --strict "$doc" || status=1
done
exit "$status"
The ./ matters: it stops a file named something like --strict.docx from being read as an option.
Convert a file whose name starts with a dash
word2html ./-draft.docx
word2html -- -draft.docx
Act on the result in a script
word2html --strict "$doc"
case $? in
0) echo "converted" ;;
3) echo "refused: needs a human to review it" ;;
*) echo "failed" ;;
esac
Convert untrusted documents on a shared machine
word2html --strict --timeout 30 --max-memory 512M --max-file-size 25M upload.docx
Then read Converting documents you don't trust, because these checks aren't a complete sanitizer.
Convert a very long document
word2html --max-memory 8G --timeout 600 book.docx