How to convert PDF files to images using RMagick and Ruby

前端 未结 3 1600
执念已碎
执念已碎 2020-12-25 09:13

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

\"Convert a .doc or .pdf to an image and display a thumbnail in Ruby?

3条回答
  •  渐次进展
    2020-12-25 09:26

    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")
    

    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.

提交回复
热议问题