Rails - 可以将PDF转换为图像? [英] Rails - Possible to convert a PDF to Images?

查看:111
本文介绍了Rails - 可以将PDF转换为图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有PaperClip / S3的Rails 3应用程序...

I have a Rails 3 app with PaperClip/S3...

是否可以允许用户上传PDF,将PDF转换为图像,以及然后上传?

Is it possible to allow a user to upload a PDF, convert the PDF to images, and then upload?

谢谢!

推荐答案

看看imagemagick和ruby的rmagick插件。这允许您进行各种图像转换,包括PDF到jpeg。

Take a look at imagemagick and rmagick plugin for ruby. This allows you to do all kinds of image conversions, including PDF to jpeg.

http://rmagick.rubyforge.org/

编辑:

未经测试示例代码:

require 'RMagick'
pdf = Magick::ImageList.new("doc.pdf")
pdf.write("myimage.jpg")

如果doc.pdf有3页,这应输出3张图片:

myimage.jpg.0

myimage.jpg.1

myimage.jpg.2

if doc.pdf has 3 pages, this should output 3 images:
myimage.jpg.0
myimage.jpg.1
myimage.jpg.2

查看此页面上文档的结尾,其中显示了使用imagelist将多帧gif转换为多个PNG的类似示例:
http://www.imagemagick.org/RMagick/doc/ilist.html#write

take a look at the end of the documentation on this page, which shows a similar example with a multi-frame gif converted to multiple PNGs using imagelist: http://www.imagemagick.org/RMagick/doc/ilist.html#write

这篇关于Rails - 可以将PDF转换为图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆