【问题标题】:Can we convert PDF, Excel, Word to Image in Ruby on Rails?我们可以在 Ruby on Rails 中将 PDF、Excel、Word 转换为图像吗?
【发布时间】:2011-09-30 05:15:56
【问题描述】:

在我的项目中,需要将PDF、Excel、Word文档转换成图片。

我知道有 imagemagick 可以用来转换 PDF,但我不确定 Excel 和 PDF 文件。

我见过JODConverter 将 Excel、Word 等转换为 PDF,然后我必须将 PDF 转换为图像。我认为 Ruby 中没有绑定 JODConverter 的 gem 或插件。

在 Ruby on Rails 平台中还有比这些更好的解决方案吗?

【问题讨论】:

    标签: ruby-on-rails excel pdf doc


    【解决方案1】:

    您可以使用 gem rmagick 将 pdf 文件转换为图像。

    这里是将所有页面保存为变量 pdf_image 中的图像的示例代码。

    pdf_image = Magick::ImageList.new('tmp/prakhar.pdf'){ self.density = 150 }
    

    然后你可以循环变量 pdf_image 并保存页面。

    # Write the image files in the tmp/images folder
        pdf_image.each_with_index do |page, index|
          page.write('tmp/images' + '/page_' + index.to_s + '.jpg')
        end
    

    【讨论】:

      猜你喜欢
      • 2020-12-09
      • 2011-05-05
      • 2011-11-16
      • 1970-01-01
      • 1970-01-01
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多