国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

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

2019-11-19 16:19:06
字體:
來源:轉載
供稿:網友

前言

想要做全文搜索引擎,則需要將word/pdf等文檔內容提取出來。對于pdf有xpdf等一些開源方案。

但Word文檔的情況則會復雜一些。

提取PDF文本內容

XPDF是一個免費開源的軟件,用于顯示PDF文件,并可將pdf轉換成文字圖片等,同樣支持Windows版。在Debian Linux上安裝非常簡單:

apt-get install xpdf

我們這里只使用pdftotext這個功能,直接輸入可查看幫助:

root@raspberrypi:/var/www# pdftotextpdftotext version 0.26.5Copyright 2005-2014 The Poppler Developers - http://poppler.freedesktop.orgCopyright 1996-2011 Glyph & Cog, LLCUsage: pdftotext [options] <PDF-file> [<text-file>] -f <int>   : first page to convert -l <int>   : last page to convert -r <fp>   : resolution, in DPI (default is 72) -x <int>   : x-coordinate of the crop area top left corner -y <int>   : y-coordinate of the crop area top left corner -W <int>   : width of crop area in pixels (default is 0) -H <int>   : height of crop area in pixels (default is 0) -layout   : maintain original physical layout -fixed <fp>  : assume fixed-pitch (or tabular) text -raw    : keep strings in content stream order -htmlmeta   : generate a simple HTML file, including the meta information -enc <string>  : output text encoding name -listenc   : list available encodings -eol <string>  : output end-of-line convention (unix, dos, or mac) -nopgbrk   : don't insert page breaks between pages -bbox    : output bounding box for each word and page size to html. Sets -htmlmeta -opw <string>  : owner password (for encrypted files) -upw <string>  : user password (for encrypted files) -q    : don't print any messages or errors -v    : print copyright and version info -h    : print usage information -help    : print usage information --help   : print usage information -?    : print usage information

測試一下:

root@raspberrypi:/var/www# pdftotext onceai.pdf onceai.txtroot@raspberrypi:/var/www# cat onceai.txt 產品介紹 頑石智能科技(上海)有限公司....

然后在node.js中使用 child_process直接調用此命令即可,pdftotext會將內容輸出以文本文件中,可能需要多一些操作。具體代碼略。

用antiword提取 .doc 的內容

我們這里使用了 antiword 開源軟件,來提取word2003以前版本的內容,安裝同樣非常簡單:

apt-get install antiword

查看幫助:

root@raspberrypi:/var/www# antiword 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.docSYNC Mobile 

主站蜘蛛池模板:
融水|
保德县|
寻乌县|
大洼县|
永嘉县|
定边县|
扶风县|
富阳市|
郸城县|
永昌县|
中山市|
修武县|
巢湖市|
仲巴县|
鹰潭市|
万盛区|
策勒县|
桓台县|
新绛县|
乌兰察布市|
泉州市|
堆龙德庆县|
浠水县|
健康|
三明市|
阳原县|
公安县|
扎赉特旗|
台安县|
永仁县|
简阳市|
资溪县|
龙岩市|
舒城县|
五原县|
南岸区|
昭苏县|
辽中县|
台南县|
唐山市|
清水河县|