Skip to content

Instantly share code, notes, and snippets.

@snaka
Created January 27, 2013 03:12
Show Gist options
  • Select an option

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

Select an option

Save snaka/4646046 to your computer and use it in GitHub Desktop.
Origami を使ってPDFから画像を抽出するスクリプト
# 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