background image

503 views
Skip to first unread message

mattia lipreri

unread,
Oct 17, 2009, 6:02:32 AM10/17/09
to prawn...@googlegroups.com
Hi,
I wanto to create a pdf in A4 size, so in my controller I added this

        prawnto :prawn => {
            :background => "#{RAILS_ROOT}/public/#{tmp_img[0]}",
            :left_margin => 0, 
            :right_margin => 0,
            :top_margin => 0,
            :bottom_margin => 0,
            :page_size => 'A4' }

which is the size og the image that will fit the A4 document? Have you any hint?
--
while ( ! ( succeed = try() ) );

Mattia Lipreri

Bryce Mecum

unread,
Oct 17, 2009, 7:32:17 PM10/17/09
to prawn...@googlegroups.com
Document::PageGeometry should help you.
http://prawn.majesticseacreature.com/docs/prawn-core/classes/Prawn/Document/PageGeometry.html

Prawn::Document::PageGeometry::SIZES["A4"]
=> [595.28, 841.89]

Gregory Brown

unread,
Oct 17, 2009, 9:12:35 PM10/17/09
to prawn...@googlegroups.com

Also note that those measurements are in 1/72 in (PDF points)

Mattia

unread,
Oct 18, 2009, 1:53:02 AM10/18/09
to prawn...@googlegroups.com
Thank you i noticed that but how can i convert it in pixel? i tried to
put an image as background with this size 595x842px, in this case
image fit correctly the PDF document but the image quality is not so
good. thanks

Mattia

Il giorno 18/ott/2009, alle ore 03.12, Gregory Brown <gregory...@gmail.com
> ha scritto:

bl4d3

unread,
Oct 18, 2009, 3:42:42 AM10/18/09
to Prawn
I tried to make an image with this size:
W: 595.28/72 inch
H: 841.89/72 inch
but the image is too big and it leaks of the document, I tried to use
the scale parameter

prawnto :prawn => {
:background => "#{RAILS_ROOT}/public/#{tmp_img[0]}",
:scale => 0.1,
:left_margin => 0,
:right_margin => 0,
:top_margin => 0,
:bottom_margin => 0,
:page_size => 'A4' }

but it does not have any effect. Thank you for your help!

On 18 Ott, 07:53, Mattia <mattia.lipr...@gmail.com> wrote:
> Thank you i noticed that but how can i convert it in pixel? i tried to  
> put an image as background with this size 595x842px, in this case  
> image fit correctly the PDF document but the image quality is not so  
> good. thanks
>
> Mattia
>
> Il giorno 18/ott/2009, alle ore 03.12, Gregory Brown <gregory.t.br...@gmail.com
>  > ha scritto:
>
>
>
>
>
> > On Sat, Oct 17, 2009 at 7:32 PM, Bryce Mecum <petrid...@gmail.com>  
> > wrote:
>
> >> Document::PageGeometry should help you.
> >>http://prawn.majesticseacreature.com/docs/prawn-core/classes/Prawn/Do...

mattia lipreri

unread,
Oct 18, 2009, 4:55:27 AM10/18/09
to Prawn
Ok, I figured out that the problem is into dpi settings, my documents dimensions are:
width 8,26 in
height 11,69 in
dpi 300
dimension in px-> w:2479 h:3508

if I set 72 dpi I get:
dimension in px-> w:595 h:842 
in this case the image fit the A4 document, but I'd like to have a better resolution, anybody know if is it possible to set the image as background at 300dpi?
--
while ( ! ( succeed = try() ) );

Mattia Lipreri


Gregory Brown

unread,
Oct 18, 2009, 10:00:07 AM10/18/09
to prawn...@googlegroups.com
On Sun, Oct 18, 2009 at 4:55 AM, mattia lipreri
<mattia....@gmail.com> wrote:
> Ok, I figured out that the problem is into dpi settings, my documents
> dimensions are:
> width 8,26 in
> height 11,69 in
> dpi 300
> dimension in px-> w:2479 h:3508
> if I set 72 dpi I get:
> dimension in px-> w:595 h:842
> in this case the image fit the A4 document, but I'd like to have a better
> resolution, anybody know if is it possible to set the image as background at
> 300dpi?

Read through the archives for discussions on the proper calculations.

-greg

mattia lipreri

unread,
Oct 18, 2009, 1:33:38 PM10/18/09
to prawn...@googlegroups.com
Hi, 
I've took a look here
but no solution is provided, I'm still stick on it, could you please give me some help? I need to set an image at 300dpi as background of my A4 document.
Thanks,
--
while ( ! ( succeed = try() ) );

Mattia Lipreri


Wojciech Piekutowski

unread,
Oct 19, 2009, 4:01:31 AM10/19/09
to prawn...@googlegroups.com
2009/10/18 mattia lipreri <mattia....@gmail.com>:
> Hi,
> I've took a look here
> http://groups.google.com/group/prawn-ruby/browse_thread/thread/21fb083d9f2be613/7fe5808a381c581b?hl=en&lnk=gst&q=dpi#7fe5808a381c581b
> but no solution is provided, I'm still stick on it, could you please give me
> some help? I need to set an image at 300dpi as background of my A4 document.

Try to use the #image method (instead of the :background option)
because it supports scaling.

Greetings,
Wojtek

mattia lipreri

unread,
Oct 19, 2009, 5:39:39 AM10/19/09
to prawn...@googlegroups.com
I made in this way:

pdf.image bg, :scale => 0.2395
pdf.move_up 841

bg is an image at 300dpi.
Thank you
--
while ( ! ( succeed = try() ) );

Mattia Lipreri


Wojciech Piekutowski

unread,
Oct 19, 2009, 5:50:55 AM10/19/09
to prawn...@googlegroups.com
2009/10/19 mattia lipreri <mattia....@gmail.com>:
> I made in this way:
> pdf.image bg, :scale => 0.2395
> pdf.move_up 841
> bg is an image at 300dpi.

I'm happy it works for you.

Just a small remark. A bit better way would be to use the :width or
:height option with a value taken from the Prawn::Document#bounds.

Greetings,
Wojtek

mattia lipreri

unread,
Oct 19, 2009, 6:09:46 AM10/19/09
to prawn...@googlegroups.com
Ok, I'll try, thanks for the support.
Another question about it, is it possible to set a background color to the document?
--
while ( ! ( succeed = try() ) );

Mattia Lipreri


Wojciech Piekutowski

unread,
Oct 19, 2009, 7:52:48 AM10/19/09
to prawn...@googlegroups.com
2009/10/19 mattia lipreri <mattia....@gmail.com>:
> Another question about it, is it possible to set a background color to the
> document?

Just use your imagination and the #fill_rectangle method.

Greetings,
Wojtek

mattia lipreri

unread,
Oct 28, 2009, 7:31:35 AM10/28/09
to prawn...@googlegroups.com
I took a look here
but there isn't any  #fill_rectangle method, how can I found any information about it?
Thank you
--
while ( ! ( succeed = try() ) );

Mattia Lipreri


Wojciech Piekutowski

unread,
Oct 28, 2009, 8:18:08 AM10/28/09
to prawn...@googlegroups.com
2009/10/28 mattia lipreri <mattia....@gmail.com>:
> I took a look here
> http://prawn.majesticseacreature.com/docs/prawn-core/
> but there isn't any  #fill_rectangle method, how can I found any information
> about it?

You can find it by reading Prawn source code (especially examples and
specs) or googling for it.

Generally you can take any shape drawing method (rectangle, curve,
line, etc) and couple it with fill_ or stroke_. Effect of
#fill_rectange is exactly the same as of #rectangle followed by #fill.
Reply all
Reply to author
Forward
0 new messages