Images in cells/tables.

78 views
Skip to first unread message

Rowan Hick

unread,
Oct 7, 2008, 10:13:39 AM10/7/08
to Prawn
Hi there,

I have a requirement to write out a pdf with images in table cells.
Looking like Prawn wants to become the gold standard I dug through the
source to see if it's possible to hack it around. So here's my
thoughts..

All the magic looks to happen in here ..
http://github.com/sandal/prawn/tree/master/lib/prawn/graphics/cell.rb

Specifically the draw method at around line 161. Right now it's
assuming it's going to get text via the @text. I propose adding a
check for an @image which would contain a new object, CellImage or
something, which is simply just a holder for the path, and what the
max height/width of the image should be. Then the normal image method
is called to actually draw in the image. All the pieces of the puzzle
seem to be there so it looks pretty simple to do.

That seems the most sensible yeah ? Any others thinking along the same
lines (or) even better have code kicking around to do it ?


Thanks,


Rowan
---
http://work.rowanhick.com
ph: +1 416 876 6656

Gregory Brown

unread,
Oct 7, 2008, 10:29:04 AM10/7/08
to prawn...@googlegroups.com
On Tue, Oct 7, 2008 at 10:13 AM, Rowan Hick <rowan...@gmail.com> wrote:

> That seems the most sensible yeah ? Any others thinking along the same
> lines (or) even better have code kicking around to do it ?

The best bet is to generalize what can be displayed in a cell. Search
for 'Section' in this email,
we've later been calling this concept an element.

http://groups.google.com/group/prawn-ruby/msg/3467f25d0506e7e7


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

john_McCaffrey

unread,
Oct 15, 2008, 5:33:05 PM10/15/08
to Prawn
I'm interested in this feature as well.
I currently have a project to display data in a table, with styled
fonts, and images in table cells. I didn't see any obvious way to
achieve what I needed to do, so I took a stab at allowing font_style,
font_color, and font_size to be specified for a cell.

While font_color and font_style seem ok, I'm not confident about
font_size enough to submit it as a patch yet, because I don't have
sufficient test coverage, and I think there are issues in calculating
cell height.

Questions:
1. Is there already a way to get font_style and font_color on a per
cell basis within a table?
2. Is there already a way to get an image and text into a cell in a
table?
3. Is there a way to get different font styles and colors within a
table cell?

I'm looking for something like this (Imagine there are just two big
cells, not 6)
| || error!(red
text) |
| cell one || expected value(black text) |
| || actual value(black or red text) |

While thinking through the design, it occurred to us that people will
most likely PRINT these pdfs, and in most cases the color would be
lost on a non-color printer. Then we started to think more about using
some clean images to denote 'success' vs. 'fail', and now I'm trying
to figure out if its possible to have a cell with an image, \n text,
\n text.

I've run all the examples (which were quite helpful), and looked
through the code, but I'll keep poking around to see if I can figure
it out.

thanks




On Oct 7, 9:29 am, "Gregory Brown" <gregory.t.br...@gmail.com> wrote:

Gregory Brown

unread,
Oct 15, 2008, 7:05:47 PM10/15/08
to prawn...@googlegroups.com
On Wed, Oct 15, 2008 at 5:33 PM, john_McCaffrey
<john.mc...@gmail.com> wrote:
>
> I'm interested in this feature as well.

I may need it for a job I'm doing, if so, big win for all of us.
However, the Ruby Mendicant hours I owe are still dedicated to cleanup
and speed optimization.
So basically... patches welcome :)

> I currently have a project to display data in a table, with styled
> fonts, and images in table cells. I didn't see any obvious way to
> achieve what I needed to do, so I took a stab at allowing font_style,
> font_color, and font_size to be specified for a cell.
>
> While font_color and font_style seem ok, I'm not confident about
> font_size enough to submit it as a patch yet, because I don't have
> sufficient test coverage, and I think there are issues in calculating
> cell height.

font_style is likely only okay for certain fonts. If you're not
re-doing the cell size calculations,
you will eventually run into spacing issues because a bold or italic
font is not necessarily the same width and height as a normal one.

> Questions:
> 1. Is there already a way to get font_style and font_color on a per
> cell basis within a table?

No

> 2. Is there already a way to get an image and text into a cell in a
> table?

No.

> 3. Is there a way to get different font styles and colors within a
> table cell?

No.

> I'm looking for something like this (Imagine there are just two big
> cells, not 6)
> | || error!(red
> text) |
> | cell one || expected value(black text) |
> | || actual value(black or red text) |
>
> While thinking through the design, it occurred to us that people will
> most likely PRINT these pdfs, and in most cases the color would be
> lost on a non-color printer. Then we started to think more about using
> some clean images to denote 'success' vs. 'fail', and now I'm trying
> to figure out if its possible to have a cell with an image, \n text,
> \n text.
>
> I've run all the examples (which were quite helpful), and looked
> through the code, but I'll keep poking around to see if I can figure
> it out.

Text is uniform across the table. To handle different fonts in
different cells, we'd need to consider this at the time of
calculation.
An interim solution are fixed width and height bounding_boxes with
borders. That's what a "Section" or "Element" will be, but it has not
been implemented yet.

-greg

Reply all
Reply to author
Forward
0 new messages