Created
January 27, 2013 03:12
-
-
Save snaka/4646046 to your computer and use it in GitHub Desktop.
Origami を使ってPDFから画像を抽出するスクリプト
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment