如何使用RMagick和Ruby将PDF文件转换为图像 [英] How to convert PDF files to images using RMagick and Ruby

查看:82
本文介绍了如何使用RMagick和Ruby将PDF文件转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取一个PDF文件并将其转换为图像,每个PDF页面都变成一个单独的图像.

I'd like to take a PDF file and convert it to images, each PDF page becoming a separate image.

"将.doc或.pdf转换为图像并用Ruby显示缩略图吗?"是类似的文章,但没有介绍如何为每个页面制作单独的图像.

"Convert a .doc or .pdf to an image and display a thumbnail in Ruby?" is a similar post, but it doesn't cover how to make separate images for each page.

推荐答案

ImageMagick 可以使用PDF做到这一点.大概 RMagick 也可以做到,但我对此并不熟悉.

ImageMagick can do that with PDFs. Presumably RMagick can do it too, but I'm not familiar with it.

您链接到的帖子中的代码:

The code from the post you linked to:

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

pdfImageList对象,根据文档将其许多方法委托给Array.您应该能够遍历pdf并调用write将单个图像写入文件.

pdf is an ImageList object, which according to the documentation delegates many of its methods to Array. You should be able to iterate over pdf and call write to write the individual images to files.

这篇关于如何使用RMagick和Ruby将PDF文件转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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