为什么我不能在Rails中使用RMagick将PDF转换为JPG?

时间:2014-01-12 20:03:00

标签: ruby-on-rails ruby pdf imagemagick rmagick

我正在尝试从Rails中的pdf创建缩略图:

def create_thumbnail
  # pdf = Magick::ImageList.new("#{Rails.root}/app/assets/images/test.pdf") # works
  pdf = Magick::ImageList.new(invoice_path(invoice, :locale => "en", :format => "pdf")) # does not work
  pdf.write("#{invoice.number}_thumbnail.jpg")
end

但是,我一直收到这个错误:

unable to open image `/en/invoices/196.pdf': No such file or directory @ error/blob.c/OpenBlob/2584`

这是我的控制者:

class InvoicesController < ApplicationController

  def show
    disposition = params[:disposition] || "inline"
    respond_to do |format|
      format.html
      format.pdf do |pdf|
        pdf = InvoicePdf.new(@invoice, view_context)
        send_data(pdf.render, :filename => invoice_filename(@invoice), :type => "application/pdf", :disposition => "inline")
      end
    end   
  end

我在这里缺少什么?

是否无法在Rails中从内联pdf生成jpeg?

感谢您的帮助。

0 个答案:

没有答案