LoginSignup
5
10

More than 5 years have passed since last update.

pdfから文字領域を表示するpdf2xml-viewer

Last updated at Posted at 2017-03-15

ともかく簡単だったのでメモ。
ただpdfの中にちゃんと文字が登録されてる場合に限る。写真の場合は無理。

スクリーンショット 2017-03-15 14.52.21.png

ソース
https://github.com/WZBSocialScienceCenter/pdf2xml-viewer

xmlに変換

pdftohtml -c -hidden -xml input.pdf output.xml

表示

python -m SimpleHTTPServer 8080

http://127.0.0.1:8080/
に接続してファイルを指定してLoad

詳細アルゴリズム

スキャンしたページイメージを抽出し、PDFのOCRテキストを含むXMLを生成する pdftohtml
pdf2xml-viewerでテキストボックスとスキャンページを表示する
ページとテキストボックスを記述するXMLを読み込む
スキャンしたページの直線を検出し、ページのスキューや回転を見つけて修正する
テーブルの列を識別するための垂直線のクラスタを検出する
テキストボックスのy座標の分布を分析して、テーブルの行位置を調べる
列と線のグリッドを作成する
テキストボックスをグリッドに一致させて、それをExcelおよびCSVファイルとしてエクスポートするために表データを抽出する


pdf2htmlEXも試してみる

写真の切り出しなどなうまくいかなかった。
pdftohtmlよりpdf2htmlEXの方が精度が高いという記事を見つけたのでpdf2htmlEXも試してみる
https://github.com/coolwanglu/pdf2htmlEX

brew install pdf2htmlEX
brew install ttfautohint
brew install xpdf

unicodeの変換対応表がない場合エラーになってる可能性あり
そもそもuni以外に変換して使えばいいのでは?
http://d.hatena.ne.jp/jeneshicc/20091122
http://www.atmarkit.co.jp/flinux/rensai/linuxtips/736pdffont.html
to unicode
http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/5411.ToUnicode.pdf

5
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
10