On Thu, May 22, 2008 at 7:49 AM, Raveendran Jazzez <jazzezravi / gmail.com> wrote:
> Hi All,
>
> My Environment:
>
>  OS: Windows, Ruby1.8.6, pdfwriter-1.1.8
>
> My need:
>
>  I have 10 jpeg images in my local system(C:\jazzezravi\1.jpg).
>  I want to write all the 10 images into one PDF format. Just now i
> installed pdf-writer gem.
>
> Thank you.

Hi,

it's easy, I think you'll find some examples either in pdfwriter docs
(http://ruby-pdf.rubyforge.org/pdf-writer/index.html),
or somewhere else on the web. Just google a bit.

If you get stuck, post the code here and somebody will try to help you.

This is my code for something similar - I do some resizing too. You
should be able to produce similar
code in a short time - everything you need is in the docs (for me the
initial version took 1-2 hours max).

J.

require 'pdf/writer'
pdf = PDF::Writer.new(:paper => "A4", :orientation => :portrait)

['1.jpg', '2.jpg', '3.jpg'].each do |jpg|
        pdf.start_new_page
        image_data = File.open(jpg, 'rb') {|f| f.read }
        image_info = PDF::Writer::Graphics::ImageInfo.new(image_data)
        p image_info.width, pdf.page_width
        p image_info.height, pdf.page_height
        ratio = [pdf.page_width/image_info.width,
pdf.page_height/image_info.height].min
        p ratio
        width = image_info.width * ratio
        height = image_info.height * ratio
        p width, height
        offset_x = (pdf.page_width - width) / 2
        offset_y = (pdf.page_height - height)

        pdf.add_image(image_data, offset_x, offset_y, width, height)
end

pdf.save_as("out.pdf")