6
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

apache pdfboxでPDFの中身のテキストを抜き出す話

Last updated at Posted at 2018-02-07

細かい経緯はこちらを参照。
https://qiita.com/arc279/items/95fbb15016a3ce34ec92

どうも手元のmacのインストール済みフォントと、pdf内で使われてるフォントの問題っぽかったので、
全部dockerにしたらあっさり解決した。

こんな感じで配置して

$ tree
.
├── docker-compose.yml
├── mnt
│   └── all.pdf
└── pdfbox-app-2.0.8.jar
docker-compose.yml
version: '2.2'
services:
  pdfbox:
    image: java:8u91
    volumes:
      - ./pdfbox-app-2.0.8.jar:/opts/pdfbox-app-2.0.8.jar
      - ./mnt:/mnt

こうすれば

docker-compose run --rm pdfbox java -jar /opts/pdfbox-app-2.0.8.jar ExtractText /mnt/all.pdf

抜き出せる

$ head mnt/all.txt
平成29年版
厚生労働白書
(平成28年度厚生労働行政年次報告)
厚 生 労 働 省
―社会保障と経済成長―
本白書は再生紙を使用しております。
第1部 社会保障と経済成長
はじめに………………………………………………………………………… 3
第1章 我が国経済社会の中の社会保障… ………………………………… 4
第1節 社会保障の役割と機能… …………………………………………………………………… 4
6
9
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
6
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?