Donato
Donato

Reputation: 2777

using imagemagick in ruby to convert pdf to png

I am trying to convert a pdf to image following this stackoverflow post.

I have imagemagick installed on mac osx via brew:

$ brew ls --versions imagemagick
imagemagick 6.8.9-5

Now I attempt to do exactly what he did in the stackoverflow answer:

> require 'RMagick'
> Dir.chdir "/Users/donato/Downloads"
> Dir.pwd
=> "/Users/donato/Downloads" 
> Dir.entries(Dir.pwd).select {|f| f =~ /sample_template.pdf/}
 => ["sample_template.pdf"]
> pdf =  Magick::ImageList.new("sample_template.pdf")
=> []
  scene= 
> pdf.class
=> Magick::ImageList
2.1.2 :017 > pdf.write "sample_template.png"
  ArgumentError: no images in this image list
  from (irb):17:in `write'
  from (irb):17
  from /Users/donato/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>'

The documentation for the write method is here.

What could I be doing wrong?

Upvotes: 1

Views: 709

Answers (1)

Donato
Donato

Reputation: 2777

Apparently, this requires a dependency called ghostscript. On Mac OSX, I used brew:

brew install gs

Now it works.

Upvotes: 3

Related Questions