我有一个 Dragonfly 处理器,它应该采用给定的 PDF 并返回文档第一页的 PNG。
当我通过控制台运行这个处理器时,我按预期返回了 PNG,但是,在 Rails 的上下文中,我将它作为 PDF 获取。
我的代码大致与此类似:
def to_pdf_thumbnail(temp_object)
tempfile = new_tempfile('png')
args = "'#{temp_object.path}[0]' '#{tempfile.path}'"
full_command = "convert #{args}"
result = `#{full_command}`
tempfile
end
def new_tempfile(ext=nil)
tempfile = ext ? Tempfile.new(['dragonfly', ".#{ext}"]) : Tempfile.new('dragonfly')
tempfile.binmode
tempfile.close
tempfile
end
现在, tempfile 肯定是在创建一个 .png 文件,但转换正在生成一个 PDF(在 Rails 3 中运行时)。
关于这里可能出现什么问题的任何想法?是否对内容类型感到困惑?
我应该补充一点,这个转换和标准转换 ( asset.png.url
) 都会生成一个 PDF,其中 PDF 内容是 (A4) 图像中间的一个小块。