docx icon indicating copy to clipboard operation
docx copied to clipboard

read pure text from docx written by Nim.

docx nimble

A dead simple docx reader.

Read pure text from docx written by Nim.

Usage

Keep only newline information.

import docx


echo parseDocument("test.docx")
for line in docLines("test.docx"):
  echo line

Output:

长记曾携手处,千树压、西湖寒碧。
I strove with none.
For none was worth my strife;
Nature I lov’d,
And next to Nature, Art;
I warm’d both hands before the fire of life;
It sinks,
and I am ready to depart.
仰天大笑出门去,我辈岂是蓬蒿人。

Only parse pure text.

import docx


echo parsePureText("test.docx")

Output:

长记曾携手处,千树压、西湖寒碧。I strove with none.For none was worth my strife;Nature I lov’d,And next to Nature, Art;I warm’d both hands before the fire of life;It sinks,and I am ready to depart.仰天大笑出门去,我辈岂是蓬蒿人。

Extract Picture from docx

let tmpDir = getTempDir()
if existsDir(tmpDir / "generate"):
  removeDir(tmpDir / "generate")
extractPicture("tests/test_pic.docx", tmpDir / "generate")
assert existsFile(tmpDir / "generate/image1.jpeg")