使用paperclip使用ghostscript将pdf转换为jpg

时间:2012-11-25 18:39:35

标签: ruby-on-rails pdf paperclip jpeg ruby-on-rails-2

我正在尝试使用以下脚本为pdf文件生成jpgs但没有成功。

https://gist.github.com/3059321

我希望有人可以为我提供一些帮助。我已经花了很多时间与它斗争。

我有一个较旧的开发环境:

shajizaidi@Spock:~/Softdev/e-mangue/script$ rails -v
Rails 2.3.8
shajizaidi@Spock:~/Softdev/e-mangue/script$ ruby -v
ruby 1.8.7 (2011-12-28 patchlevel 357) [i686-linux]

相关的宝石:

aasm (3.0.1)
actionmailer (2.3.8, 2.2.2)
actionpack (2.3.8, 2.2.2)
activemodel (3.1.3)
activerecord (2.3.8, 2.2.2)
activeresource (2.3.8, 2.2.2)
activesupport (3.1.3, 2.3.8, 2.2.2)
arel (2.2.1)
git (1.2.5)
hpricot (0.8.5)
httpclient (2.2.4)
mysql (2.8.1)
passenger (3.0.11)
rack (1.4.0, 1.1.3)
rails (2.3.8, 2.2.2)
rake (0.9.2)
ruby-blockcache (0.2)
rubygems-update (1.5.3)
rubyist-aasm (2.1.1)
soap4r (1.5.8)

我的模型的摘录如下:

class Issue < ActiveRecord::Base
include AASM

   belongs_to :publication
   has_many :readings
   has_many :readers, :through => :readings, :class_name => "User"

   has_many :issue_metadatas, :dependent => :destroy
   has_many :table_of_contents_entries, :dependent => :destroy

   has_many :issue_ratings

   has_one :issue_status, :dependent => :destroy

   has_attached_file :pdf,
                    :url  => "/assets/:id/",
                    :path => ":rails_root/assets/docs/:id/:style/:basename.:extension",
                     :styles => {
                                 :icon => ["60X80#", :jpg], 
                                 :thumb => ["360x480#", :jpg]
                                 :large => ["X800", :jpg]
                                 },
                     :processors => [:ghostscript, :thumbnail],
                     :convert_options => {:all => ' colorspace RGB  flatten  density 300  quality 100'},
                     :path => ":page_path/:class/:id/:resource_token/:style/:filename"

   validates_presence_of     :issue_number
   validates_presence_of     :title
   validates_presence_of     :date

当我尝试上传pdf时,我收到以下错误:

 RuntimeError (cannot generate tempfile `'):
  /home/shajizaidi/.rvm/rubies/ruby-1.8.7-p357/lib/ruby/1.8/tempfile.rb:52:in `initialize'
  lib/paperclip_processors/ghostscript.rb:17:in `new'
  lib/paperclip_processors/ghostscript.rb:17:in `make'
  app/controllers/issues_controller.rb:79:in `new'
  app/controllers/issues_controller.rb:79:in `create'

ghostscript.rb

测试我是否通过不使用数组来改变生成临时文件的方式,例如:

dst = Tempfile.new(“#@basename})

而不是:

dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])

我没有得到错误;但是当然没有正确生成临时文件的文件名。

我试图对此进行相当多的研究,似乎无法找到解决方案。

0 个答案:

没有答案