Created
February 2, 2013 00:48
-
-
Save snaka/4695309 to your computer and use it in GitHub Desktop.
Origami で PDF に埋めこまれている画像を抽出する ref: http://qiita.com/items/768497d84e6bf8594d6b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| require 'origami' | |
| include Origami | |
| pdf = PDF.read(ARGV[0]) | |
| images = pdf.root_objects.find_all {|obj| obj.is_a?(Graphics::ImageXObject)} | |
| images.each do |stream| | |
| ext, image_data = stream.to_image_file | |
| image_file = "image_#{stream.reference.refno}.#{ext}" | |
| File.open(image_file, "wb") do |f| | |
| f.write(image_data) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ ruby extract_images.rb PDFファイル名 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment