如何使用Carrierwave在rails中将PDF的第一页作为图像?

cro*_*don 6 ruby-on-rails carrierwave

Imagemagick和mini_magick gem都已安装,但我上传pdf时无法保存模型.

在尝试创建模型的新实例时,我收到以下错误:

Pdf Failed to manipulate with MiniMagick, maybe it is not an image?

我在这做错了什么?我的意图是使用以下所示的解决方案:http://afreshcup.com/home/2012/9/27/thumbnailing-pdfs-with-minimagick.html

我的上传者:

class PrivatePdfUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  storage :file

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  def default_url
    "/images/fallback/" + [version_name, "default.png"].compact.join('_')
  end

  version :web_thumb do
    process :thumbnail_pdf
  end

  def thumbnail_pdf
    manipulate! do |img|
      img.format("png", 1)
      img.resize("150x150")
      img = yield(img) if block_given?
      img
    end
  end

end
Run Code Online (Sandbox Code Playgroud)

Yur*_*dev 4

你安装了吗ghostscript

brew install ghostscript
Run Code Online (Sandbox Code Playgroud)