かすみん日記

暇なときに何か喋ります

PDFから画像を抽出

Xpdfpdfimages コマンドで、PDFから画像データを抽出する。

「変換」ではなく「抽出」です。

お金持ちの人はAdobeAcrobatを使えばいいです。

Xpdfのインストール(mac

macの人は、homebrewでxpdfをインストールする;

brew install xpdf

linuxの人は apt-get でインストール(?)。

winの人は手動で?

Xpdfのインストール(手動)

ダウンロード

www.xpdfreader.com

上記サイトの「Downloads」->「Download the Xpdf command line tools:」から、自分のOSに合ったものを選んでダウンロード。

ダウンロードできたら、圧縮ファイルを解凍する。

実行ファイルの配置

あとはテキストファイル INSTALL に書かれてる手順に従ってコマンドをインストールする。

使い方

画像を抽出したいPDFファイル(hoge.pdf)のあるディレクトリに移動して、次のようにコマンドを実行;

pdfimages -j hoge.pdf foo

すると、同階層に抽出された画像が連番で生成される;

foo-001.jpg
foo-002.jpg
...

ここで -j オプションはjpg画像はjpg画像として抽出するために必要。

オプションの説明

pdfimages -h
pdfimages version 4.02
Copyright 1996-2019 Glyph & Cog, LLC
Usage: pdfimages [options] <PDF-file> <image-root>
  -f <int>       : first page to convert
  -l <int>       : last page to convert
  -j             : write JPEG images as JPEG files
  -raw           : write raw data in PDF-native formats
  -list          : write information to stdout for each image
  -opw <string>  : owner password (for encrypted files)
  -upw <string>  : user password (for encrypted files)
  -q             : don't print any messages or errors
  -cfg <string>  : configuration file to use in place of .xpdfrc
  -v             : print copyright and version info
  -h             : print usage information
  -help          : print usage information
  --help         : print usage information
  -?             : print usage information

マニュアル

man pdfimages

q で終了。