Skip to content

Instantly share code, notes, and snippets.

@snaka
Created February 2, 2013 00:48
Show Gist options
  • Select an option

  • Save snaka/4695309 to your computer and use it in GitHub Desktop.

Select an option

Save snaka/4695309 to your computer and use it in GitHub Desktop.
Origami で PDF に埋めこまれている画像を抽出する ref: http://qiita.com/items/768497d84e6bf8594d6b
# 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
$ ruby extract_images.rb PDFファイル名
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment