最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2017年06月17日 14:53:36   作者:kris  
這篇文章主要給大家介紹了關于Linux系統(tǒng)中利用node.js提取Word(doc/docx)及PDF文本的內容,文中給出了詳細的示例代碼供大家參考學習,需要的朋友們下面跟著小編來一起看看吧。

前言

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

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

提取PDF文本內容

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

apt-get install xpdf

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

root@raspberrypi:/var/www# pdftotext
pdftotext version 0.26.5
Copyright 2005-2014 The Poppler Developers - http://poppler.freedesktop.org
Copyright 1996-2011 Glyph & Cog, LLC
Usage: 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.txt
root@raspberrypi:/var/www# cat onceai.txt 產(chǎn)品介紹 頑石智能科技(上海)有限公司
....

然后在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.doc

SYNC Mobile – Ford APA
Project Number: DFYST
Requirements Specification

同樣在node.js用child_process調用此命令即可。

解析提取.docx 的內容

對于 docx 文檔來說,因基本身就是一個zip文件,只需要在node.js先將其解壓,再解析 text.docx\word\document.xml 文件即可。

Github上也有些將docx解析成html的庫,

如:

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

https://github.com/lalalic/docx2html 

等。

總結

以上就是這文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關文章

  • nodejs中實現(xiàn)阻塞實例

    nodejs中實現(xiàn)阻塞實例

    這篇文章主要介紹了nodejs中實現(xiàn)阻塞實例,本文直接給出實例代碼,需要的朋友可以參考下
    2015-03-03
  • express的中間件basicAuth詳解

    express的中間件basicAuth詳解

    這篇文章主要介紹了node.js中express的中間件basicAuth的使用方法,需要的朋友可以參考下
    2014-12-12
  • node.js實現(xiàn)快速截圖

    node.js實現(xiàn)快速截圖

    本文給大家匯總介紹了幾種node.js實現(xiàn)快速截屏的方法,這里分享給大家,希望大家能夠喜歡。
    2016-08-08
  • require加載器實現(xiàn)原理的深入理解

    require加載器實現(xiàn)原理的深入理解

    這篇文章主要給大家介紹了關于require加載器實現(xiàn)原理的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-04-04
  • node.JS路徑解析之PATH模塊使用方法詳解

    node.JS路徑解析之PATH模塊使用方法詳解

    path模塊包含一系列處理和轉換文件路徑的工具集,通過 require('path') 可用來訪問這個模塊。本文將詳細介紹path模塊
    2020-02-02
  • 使用nodejs下載風景壁紙

    使用nodejs下載風景壁紙

    本文主要介紹了使用nodejs下載風景壁紙的方法。具有一定的參考價值,下面跟著小編一起來看下吧
    2017-02-02
  • Node.js中fs模塊實現(xiàn)配置文件的讀寫操作

    Node.js中fs模塊實現(xiàn)配置文件的讀寫操作

    在Node.js中, fs模塊提供了對文件系統(tǒng)的訪問功能,我們可以利用它來實現(xiàn)配置文件的讀取和寫入操作,這篇文章主要介紹了Node.js中fs模塊實現(xiàn)配置文件的讀寫,需要的朋友可以參考下
    2024-04-04
  • node.js中使用ejs渲染數(shù)據(jù)的代碼實現(xiàn)

    node.js中使用ejs渲染數(shù)據(jù)的代碼實現(xiàn)

    這篇文章主要介紹了node.js中使用ejs渲染數(shù)據(jù),本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2023-11-11
  • Node.js API詳解之 assert模塊用法實例分析

    Node.js API詳解之 assert模塊用法實例分析

    這篇文章主要介紹了Node.js API詳解之 assert模塊用法,結合實例形式分析了Node.js API中assert模塊基本函數(shù)、功能、用法及操作注意事項,需要的朋友可以參考下
    2020-05-05
  • 淺談Node.js 沙箱環(huán)境

    淺談Node.js 沙箱環(huán)境

    本篇文章主要介紹了Node.js 沙箱環(huán)境 ,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05

最新評論

肃南| 巨野县| 盖州市| 河北区| 邹城市| 永清县| 皮山县| 古蔺县| 宁阳县| 郓城县| 定远县| 万荣县| 察隅县| 富蕴县| 和平县| 上蔡县| 郁南县| 嘉禾县| 靖边县| 都匀市| 法库县| 泸西县| 弥勒县| 淳化县| 万全县| 大邑县| 保定市| 台山市| 林周县| 宕昌县| 嘉兴市| 巴彦淖尔市| 新民市| 分宜县| 彭阳县| 阿尔山市| 合阳县| 绿春县| 万源市| 康保县| 泰来县|