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

How to get the first page of a PDF as an image using Carrierwave in rails?

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

你安装了ghostscript了吗?

brew install ghostscript