Linux系统中利用node.js提取Word(doc/docx)及PDF文本的内容

2020-06-17 06:39:00易采站长站整理

Name: antiword
Purpose: Display MS-Word files
Author: (C) 1998-2005 Adri van Os
Version: 0.37 (21 Oct 2005)
Status: GNU General Public License
Usage: antiword [switches] wordfile1 [wordfile2 ...] Switches: [-f|-t|-a papersize|-p papersize|-x dtd][-m mapping][-w #][-i #][-Ls] -f formatted text output
-t text output (default)
-a <paper size name> Adobe PDF output
-p <paper size name> PostScript output
paper size like: a4, letter or legal
-x <dtd> XML output
like: db (DocBook)
-m <mapping> character mapping file
-w <width> in characters of text output
-i <level> image level (PostScript only)
-L use landscape mode (PostScript only)
-r Show removed text
-s Show hidden (by Word) text

antiword直接将word内容输出到了console中:


root@raspberrypi:/var/www# antiword spec.doc

SYNC Mobile – Ford APA
Project Number: DFYST
Requirements Specification

同样在node.js用child_process调用此命令即可。

解析提取.docx 的内容

对于 docx 文档来说,因基本身就是一个zip文件,只需要在node.js先将其解压,再解析 text.docxworddocument.xml 文件即可。

Github上也有些将docx解析成html的库,

如:

https://github.com/mwilliamson/mammoth.js 

https://github.com/lalalic/docx2html 

等。

总结

以上就是这文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如有疑问大家可以留言交流,谢谢大家对软件开发网的支持。