You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Steve Edwards <st...@yahoo.com> on 2003/08/01 22:44:45 UTC

How do I fit a table to a page?

Here's my problem: I want to write a generic java
method capable of writing various size tables to a PDF
file in a fit-to-page manner.  I will generate a
PDF-FO stylesheet and feed it to the FOP engine
directly inside the method, therefore there is no XSLT
involved.  However, each table is different in terms
of the number of rows and columns it contains.

What I need to know is whether there is an easier way
than what I propose below.  Did I forget anything big?
 Thanks in advance for any help you can offer!


Proposal
--------

1.  I will have some default font-size, perhaps 10pt. 
If the table generated with this size font is small
enough to fit on the page (I'm really just talking
width here, I will let FOP line-break the table and
continue on the next page if necessary), then make the
table just wide enough to contain everything then put
it on the page centered horizontally.  If the table
would be too wide to fit with a 10pt font, use a font
just small enough to make it fit.  The table would
appear on the page at or very near the full available
width.

2. To do this right I believe I need to embed a
TrueType font in the PDF.  If I understand the nature
of TrueType correctly, this means I can choose
whatever pt size I want without worrying whether it is
actually present or not in the font definition.  When
I generate the font metrics with TTFReader, it looks
like I will be best off using the "-enc ansi" option.

3. My method will first look at all the data in the
table and determine the maximum width required by each
column.  Sum all of these and do some calculations to
determine the size font required to fill the entire
width of the page (this is minus margins, of course).
If it's greater than 10pt, just use 10pt instead.  In
this case the width of the table will need to be
calculated so that it is smaller than the full
available width on the page.  I'm just doing this to
avoid vast amounts of whitespace in my table.

4.  The table-column tags will set the column-width
attribute equal to "proportional-column-width(x)",
where x is the maximum width determined for that
column.  This should set all the column widths correctly.

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org