詳しい解説は抜きにして、PDFに貼り付けらている画像ファイルを取り出す方法。
画像を取り出すにはpdfimageコマンド
PDFから画像を抜き出す
pdfimages -j in.pdf out
-j オプションは出力をjpgで取り出すオプション。つけたほうがイイ
pdfimageは何をしているのか
man に詳しく載っている。
PDFファイル中に梅子rまれた PPMを探して、見つけたら保存している。
DESCRIPTION Pdfimages saves images from a Portable Document Format (PDF) file as Portable Pixmap (PPM), Portable Bitmap (PBM), or JPEG files. Pdfimages reads the PDF file, scans one or more pages, PDF-file, and writes one PPM, PBM, or JPEG file for each image, image-root-nnn.xxx, where nnn is the image number and xxx is the image type (.ppm, .pbm, .jpg). NB: pdfimages extracts the raw image data from the PDF file, without performing any additional transforms. Any rotation, clipping, color inversion, etc. done by the PDF content stream is ignored.
画像の向きが変わるんだけど?
そういうものです。PDFに画像ファイル添付するとき、向きだとか色指定とかそういうことを表示制御(印刷用制御?)しているんだけどそのデータも落ちるから、本当に添付されている画像だけが出てくる。向きだとかはimagemagick で修正すればいいでしょう。
何も出てこないんだけど?
それ画像が添付されていないPDFじゃないでしょうか。Wordから作られたPDFファイルなど、文字選択が出来るPDFファイルは、画像が含まれないので、出力はありません。
2017-01-10 追記
pdfimages コマンドが popplerに含まれていて、コレも同じことが出来るようです。
brew install poppler