table position

46 views
Skip to first unread message

macsig

unread,
Aug 27, 2008, 1:40:55 AM8/27/08
to Prawn
Hello, is it possible to define where a table should be placed?
Something like :at => [x,y] for text

Moreover, I found the option to show the total number of pages, is it
possible to show the current page number?


Thank you and have a nice day!

Gregory Brown

unread,
Aug 27, 2008, 1:45:33 AM8/27/08
to prawn...@googlegroups.com
On Wed, Aug 27, 2008 at 1:40 AM, macsig <sigb...@gmail.com> wrote:
>
> Hello, is it possible to define where a table should be placed?
> Something like :at => [x,y] for text

You can use a bounding box for that.

bounding_box([100,500]) do
table data, ...
end

You can also set the x position of a table with :position => xpos

> Moreover, I found the option to show the total number of pages, is it
> possible to show the current page number?

page_count will always be the current page number, as your pages are
finalized each time a new one begins.
We don't currently have a way of getting the 'true' total page count.


--
Technical Blaag at: http://blog.majesticseacreature.com | Non-tech
stuff at: http://metametta.blogspot.com

macsig

unread,
Aug 27, 2008, 1:02:50 PM8/27/08
to Prawn
Hello Gregory and thanks for you reply.

I have some issue with the bounding box:

My code looks like:

Prawn::Document.generate("doc.pdf", :page_layout => :landscape) do

img = "#{RAILS_ROOT}/public/images/img.png"
image img, :at => [0,500], :scale => 0.50

bounding_box([10,500]) do
data = ["a","b"]


table data,
:position => :center,
:font_size => 10,
:headers => ["1","2"],
:row_colors => ["ffffff", "c2ced7"],
:vertical_padding => 4,
:horizontal_padding => 3
end
end

and I get a "comparison of Float with nil failed" error

/Library/Ruby/Gems/1.8/gems/prawn-0.1.2/lib/prawn/document/table.rb:
159:in `calculate_column_widths'
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/
inflector.rb:257:in `each_with_index'
/Library/Ruby/Gems/1.8/gems/prawn-0.1.2/lib/prawn/document/table.rb:
155:in `each'
/Library/Ruby/Gems/1.8/gems/prawn-0.1.2/lib/prawn/document/table.rb:
155:in `each_with_index'
/Library/Ruby/Gems/1.8/gems/prawn-0.1.2/lib/prawn/document/table.rb:
155:in `calculate_column_widths'
/Library/Ruby/Gems/1.8/gems/prawn-0.1.2/lib/prawn/document/table.rb:
154:in `each'
/Library/Ruby/Gems/1.8/gems/prawn-0.1.2/lib/prawn/document/table.rb:
154:in `calculate_column_widths'
/Library/Ruby/Gems/1.8/gems/prawn-0.1.2/lib/prawn/document/table.rb:
120:in `initialize'
/Library/Ruby/Gems/1.8/gems/prawn-0.1.2/lib/prawn/document/table.rb:
41:in `new'
/Library/Ruby/Gems/1.8/gems/prawn-0.1.2/lib/prawn/document/table.rb:
41:in `table'

Am I missing something?

Thanks again and have a nice day!




On Aug 26, 10:45 pm, "Gregory Brown" <gregory.t.br...@gmail.com>
wrote:

Gregory Brown

unread,
Aug 27, 2008, 1:04:53 PM8/27/08
to prawn...@googlegroups.com
On Wed, Aug 27, 2008 at 1:02 PM, macsig <sigb...@gmail.com> wrote:
>
> Hello Gregory and thanks for you reply.
>
> I have some issue with the bounding box:
>
> My code looks like:
>
> Prawn::Document.generate("doc.pdf", :page_layout => :landscape) do
>
> img = "#{RAILS_ROOT}/public/images/img.png"
> image img, :at => [0,500], :scale => 0.50
>
> bounding_box([10,500]) do
> data = ["a","b"]
>
>
> table data,
> :position => :center,
> :font_size => 10,
> :headers => ["1","2"],
> :row_colors => ["ffffff", "c2ced7"],
> :vertical_padding => 4,
> :horizontal_padding => 3
> end
> end

> Am I missing something?

Yes. data needs to be a two dimensional array, representing an array
of rows of cells.

data = [["a","b"]]

I'll work on throwing a better error message, please drop a ticket in
Lighthouse to remind me.

-greg

Gregory Brown

unread,
Aug 27, 2008, 1:06:36 PM8/27/08
to prawn...@googlegroups.com
On Wed, Aug 27, 2008 at 1:04 PM, Gregory Brown
<gregory...@gmail.com> wrote:
> On Wed, Aug 27, 2008 at 1:02 PM, macsig <sigb...@gmail.com> wrote:
>>
>> Hello Gregory and thanks for you reply.
>>
>> I have some issue with the bounding box:
>>
>> My code looks like:
>>
>> Prawn::Document.generate("doc.pdf", :page_layout => :landscape) do
>>
>> img = "#{RAILS_ROOT}/public/images/img.png"
>> image img, :at => [0,500], :scale => 0.50
>>
>> bounding_box([10,500]) do
>> data = ["a","b"]
>>
>>
>> table data,
>> :position => :center,
>> :font_size => 10,
>> :headers => ["1","2"],
>> :row_colors => ["ffffff", "c2ced7"],
>> :vertical_padding => 4,
>> :horizontal_padding => 3
>> end
>> end
>
>> Am I missing something?

Whoops:

You also need to specify a width for your bounding box.

macsig

unread,
Aug 27, 2008, 1:16:42 PM8/27/08
to Prawn
My bad, simplifying the code to post I have deleted [],


Now my code looks like:
Prawn::Document.generate("doc.pdf", :page_layout => :landscape) do
img = "#{RAILS_ROOT}/public/images/img.png"
image img, :at => [0,500], :scale => 0.50
bounding_box([10,500]) do
data = [["a","b"]]
table data,
:position => :center,
:font_size => 10,
:headers => ["1","2"],
:row_colors => ["ffffff", "c2ced7"],
:vertical_padding => 4,
:horizontal_padding => 3
end
end
and I get a "You have a nil object when you didn't expect it! You
might have expected an instance of Array. The error occurred while
evaluating nil." error
and the line with error is table data. Removing the box everything
works fine.

Am I still missing something?

Thanks buddy.

Gregory Brown

unread,
Aug 27, 2008, 1:20:11 PM8/27/08
to prawn...@googlegroups.com
On Wed, Aug 27, 2008 at 1:16 PM, macsig <sigb...@gmail.com> wrote:
>

> Am I still missing something?

Yes. All bounding_box calls require a :width parameter.

I'll add a better error for this, too.

macsig

unread,
Aug 27, 2008, 1:27:45 PM8/27/08
to Prawn
got it !!!

Thanks

a ticket about the first error message has been open

On Aug 27, 10:20 am, "Gregory Brown" <gregory.t.br...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages