Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Write images in PDF format
Raveendran Jazzez
5/22/2008 5:50:00 AM
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.
Regards,
P.Raveendran
RailsFactory
http://raveendran.wor...
--
Posted via
http://www.ruby-...
.
1 Answer
Jano Svitok
5/22/2008 9:09:00 AM
0
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/...
),
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")
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Write images in PDF format
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password