Simmo
Simmo

Reputation: 1719

How do I combine a number of images into a single PDF using ruby?

I have an array of images. How can I combine them into a PDF, with one image per page?

I've taken a look at RGhost and RMagic and the answer might be in there somewhere but it's eluding me right now.

Upvotes: 5

Views: 4190

Answers (2)

Малъ Скрылевъ
Малъ Скрылевъ

Reputation: 16507

Have a look into prawn gem. Simple example see below:

require 'prawn'

Prawn::Document.generate('hello.pdf') do |pdf|
   pdf.text("Hello Prawn!")
   pdf.image "#{Prawn::DATADIR}/images/fractal.jpg", :at => [200, 100]
end

Upvotes: 6

Stefan
Stefan

Reputation: 114138

You can use RMagick's ImageList#write:

If the image format indicated by the filename supports multiple images per file (animated images), write writes all the images in the imagelist to a single file.

Example:

require 'rmagick'

image_list = Magick::ImageList.new("image1.png", "image2.png", "image3.png")
image_list.write("images.pdf")

Upvotes: 6

Related Questions