HiiHahWIKI - making some notes for... -
Linux:pdftotextコマンドでPDFからテキストを抽出
をテンプレートにして作成
開始行:
*Linux:pdftotextコマンドでPDFからテキストを抽出 [#jb60be...
apacheTikaをつかってPDFからテキストを抽出していたけど、縦...
いろいろ調べたところ、CentOS6系では、popplerというPDFソフ...
popplerとは、xPDFというOSSからフォークしたソフトらしい。
-xPDF:http://ja.wikipedia.org/wiki/Xpdf
-Poppler:http://ja.wikipedia.org/wiki/Poppler
このPopplerはCentOS6系では標準で使用できるようです。
使えるかどうかはyumで確認できます。
# yum list poppler poppler-utils
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
* base: ftp.jaist.ac.jp
* extras: ftp.jaist.ac.jp
* updates: ftp.jaist.ac.jp
Installed Packages
poppler.x86_64 0.12.4-3.el6_0.1 @anaconda-C...
poppler-utils.x86_64 0.12.4-3.el6_0.1 @anaconda-C...
Available Packages
poppler.i686 0.12.4-3.el6_0.1 base ...
このpoppler-utilsにいろいろなコマンドが含まれています。
-pdffonts
-pdfimages
-pdfinfo
-pdftohtml
-pdftops
-pdftotext
このpdftotextコマンドを使用してPDFからテキストを抽出しま...
ヘルプ出力は以下の通り。
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 l...
-y <int> : y-coordinate of the crop area top l...
-W <int> : width of crop area in pixels (defau...
-H <int> : height of crop area in pixels (defa...
-layout : maintain original physical layout
-raw : keep strings in content stream order
-htmlmeta : generate a simple HTML file, includ...
-enc <string> : output text encoding name
-listenc : list available encodings
-eol <string> : output end-of-line convention (unix...
-nopgbrk : don't insert page breaks between pa...
-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
***使い方 [#a15f945e]
基本的な使い方は以下の通り。
pdftotext [PDFファイル] [出力先]
pdftotext test.pdf text.pdf.txt
ちなみに、出力先に「-」(ハイフン)を指定すると標準出力に...
pdftotext test.pdf
ただ、オプションなしだと縦書きPDFは正しく出力されないよう...
pdftotext -raw test.pdf test.pdf.txt
これで出力すると、1文字ずつ改行されたテキストが出力される...
pdftotext -raw test.pdf - | sed ':loop; N; $!b loop; ;s/...
こんな感じでいい感じの出力になります。
ちなみに、先頭のXバイトだけ出力する場合はこんな感じです。
pdftotext -raw test.pdf - | sed ':loop; N; $!b loop; ;s/...
さらに、inputディレクトリにあるすべのファイルを読み込んで...
IN_DIR="./input"
OUT_DIR="./output_cut"
LIST=`ls -1 ${IN_DIR}`
for LINE in ${LIST}
do
pdftotext -raw ${IN_DIR}/${LINE} -| sed ':loop; N; $!b...
done
ふむふむ、簡単ですなw
終了行:
*Linux:pdftotextコマンドでPDFからテキストを抽出 [#jb60be...
apacheTikaをつかってPDFからテキストを抽出していたけど、縦...
いろいろ調べたところ、CentOS6系では、popplerというPDFソフ...
popplerとは、xPDFというOSSからフォークしたソフトらしい。
-xPDF:http://ja.wikipedia.org/wiki/Xpdf
-Poppler:http://ja.wikipedia.org/wiki/Poppler
このPopplerはCentOS6系では標準で使用できるようです。
使えるかどうかはyumで確認できます。
# yum list poppler poppler-utils
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
* base: ftp.jaist.ac.jp
* extras: ftp.jaist.ac.jp
* updates: ftp.jaist.ac.jp
Installed Packages
poppler.x86_64 0.12.4-3.el6_0.1 @anaconda-C...
poppler-utils.x86_64 0.12.4-3.el6_0.1 @anaconda-C...
Available Packages
poppler.i686 0.12.4-3.el6_0.1 base ...
このpoppler-utilsにいろいろなコマンドが含まれています。
-pdffonts
-pdfimages
-pdfinfo
-pdftohtml
-pdftops
-pdftotext
このpdftotextコマンドを使用してPDFからテキストを抽出しま...
ヘルプ出力は以下の通り。
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 l...
-y <int> : y-coordinate of the crop area top l...
-W <int> : width of crop area in pixels (defau...
-H <int> : height of crop area in pixels (defa...
-layout : maintain original physical layout
-raw : keep strings in content stream order
-htmlmeta : generate a simple HTML file, includ...
-enc <string> : output text encoding name
-listenc : list available encodings
-eol <string> : output end-of-line convention (unix...
-nopgbrk : don't insert page breaks between pa...
-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
***使い方 [#a15f945e]
基本的な使い方は以下の通り。
pdftotext [PDFファイル] [出力先]
pdftotext test.pdf text.pdf.txt
ちなみに、出力先に「-」(ハイフン)を指定すると標準出力に...
pdftotext test.pdf
ただ、オプションなしだと縦書きPDFは正しく出力されないよう...
pdftotext -raw test.pdf test.pdf.txt
これで出力すると、1文字ずつ改行されたテキストが出力される...
pdftotext -raw test.pdf - | sed ':loop; N; $!b loop; ;s/...
こんな感じでいい感じの出力になります。
ちなみに、先頭のXバイトだけ出力する場合はこんな感じです。
pdftotext -raw test.pdf - | sed ':loop; N; $!b loop; ;s/...
さらに、inputディレクトリにあるすべのファイルを読み込んで...
IN_DIR="./input"
OUT_DIR="./output_cut"
LIST=`ls -1 ${IN_DIR}`
for LINE in ${LIST}
do
pdftotext -raw ${IN_DIR}/${LINE} -| sed ':loop; N; $!b...
done
ふむふむ、簡単ですなw
ページ名: