Hello Bruno!
My modification was only working with tables having header cells .. here is
a bug fix to have it working for tables without header cells as well (again
in the PdfDocument.add(Element) method):
// new page
newPage();
// Bug fix start Gerald Fehringer: if something added through page
event
boolean somethingAdded = false;
if( currentHeight > 0 )
{
somethingAdded = true;
newLine();
flushLines();
indentTop = currentHeight - leading + 6;
currentHeight = 0;
}
else
{
flushLines();
}
// Bug fix end
// this part repeats the table headers (if any)
headercells = table.getHeaderCells();
int size = headercells.size();
if (size > 0) {
// this is the top of the headersection
cell = (PdfCell) headercells.get(0);
float oldTop = cell.top();
// loop over all the cells of the table header
for (int i = 0; i < size; i++) {
cell = (PdfCell) headercells.get(i);
// calculation of the new cellpositions
cell.setTop(indentTop()- oldTop + cell.top());
cell.setBottom(indentTop()- oldTop + cell.bottom() - 2f *
table.cellspacing());
pagetop = cell.bottom();
// we paint the borders of the cell
cellGraphics.rectangle(cell.rectangle(indentTop(),
indentBottom()));
// we write the text of the cell
ArrayList images = cell.getImages(indentTop(), indentBottom());
for (Iterator im = images.iterator(); im.hasNext(); ) {
cellsShown = true;
Image image = (Image) im.next();
addImage(graphics, image, 0, 0, 0, 0, 0, 0);
}
lines = cell.getLines(indentTop(), indentBottom());
float cellTop = cell.top(indentTop());
text.moveText(0, cellTop);
cellDisplacement = flushLines() - cellTop;
text.moveText(0, cellDisplacement);
}
currentHeight = indentTop() - pagetop - table.cellspacing();
text.moveText(0, pagetop - indentTop() + table.cellspacing() -
currentHeight);
}
// Bug fix start Gerald Fehringer: if no header cells and something
added through page event
else
{
if( somethingAdded )
{
pagetop = indentTop();
text.moveText(0, pagetop - indentTop() + table.cellspacing());
}
}
// Bug fix end
oldHeight = currentHeight;
Kind regards,
Gerald.
----- Original Message -----
From: "Gerald Fehringer" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, October 01, 2002 3:10 PM
Subject: Re: [iText-questions] Table as header ?
> I have managed to make my example working now :-)
>
> Have modified PdfDocument.add(Element) method for the case of TABLE .. in
> case a new page is triggered now I adjust the indentTop and currentHeight
> (if required i.e. currentHeight > 0, this is somewhat similar to when a
> header object is added to the document):
>
> // new page
> newPage();
> if( currentHeight > 0 )
> {
> newLine();
> flushLines();
> indentTop = currentHeight - leading + 6;
> currentHeight = 0;
> }
> else
> {
> flushLines();
> }
>
> Hope this change will be included in the next version, should help lots of
> people trying to add headers.
>
> Kind regards,
> Gerald.
>
> PS: If you run the example sent in my previous mail you will notice some
bug
> with cell borders not being drawn if a cell contains multiple lines and is
> split onto 2 pages (see attached PDF).
>
> ----- Original Message -----
> From: "Paulo Soares" <[EMAIL PROTECTED]>
> To: "'Gerald Fehringer'" <[EMAIL PROTECTED]>;
> <[EMAIL PROTECTED]>
> Sent: Tuesday, October 01, 2002 12:29 PM
> Subject: RE: [iText-questions] Table as header ?
>
>
> > Page events only work with absolute positioned objects. You'll have to
use
> a
> > PdfPTable.
> >
> > Best Regards,
> > Paulo Soares
> >
> > > -----Original Message-----
> > > From: Gerald Fehringer [SMTP:[EMAIL PROTECTED]]
> > > Sent: Tuesday, October 01, 2002 11:17
> > > To: [EMAIL PROTECTED]
> > > Subject: Re: [iText-questions] Table as header ?
> > >
> > > I have done a small example which shows what I'd like to achieve ..
> > > attached
> > > you will find that example ..
> > >
> > > Using the MyPageEvent I'm adding a table on each onStartPage() to the
> > > document, this table represents the header of my document.
> > > The main content of the document is another table which spans multiple
> > > pages.
> > > The problem I have is the following: when starting the second page my
> > > header
> > > table gets added and then the main data table continues to be drawn
but
> > > with
> > > wrong coordinates .. (see attached PDF).
> > >
> > > What can I do?
> > >
> > > Kind regards,
> > > Gerald.
> > >
> > > ----- Original Message -----
> > > From: "Paulo Soares" <[EMAIL PROTECTED]>
> > > To: "'Gerald Fehringer'" <[EMAIL PROTECTED]>;
> > > <[EMAIL PROTECTED]>
> > > Sent: Tuesday, October 01, 2002 11:58 AM
> > > Subject: RE: [iText-questions] Table as header ?
> > >
> > >
> > > > Unless you are using rowspan changing a Table into a PdfPTable is
> > > trivial.
> > > > If you have rowspan then it has to be converted to nested tables and
> the
> > > > difficulty changes from trivial to easy. What's really your problem?
> > > >
> > > > Best Regards,
> > > > Paulo Soares
> > > >
> > > > > -----Original Message-----
> > > > > From: Gerald Fehringer [SMTP:[EMAIL PROTECTED]]
> > > > > Sent: Tuesday, October 01, 2002 8:54
> > > > > To: [EMAIL PROTECTED]
> > > > > Subject: Re: [iText-questions] Table as header ?
> > > > >
> > > > > Seems to be a difficult question :-)
> > > > >
> > > > > Any thoughts as yet?
> > > > > Any hint on what I could do?
> > > > >
> > > > > Regards,
> > > > > Gerald.
> > > > >
> > > > > ----- Original Message -----
> > > > > From: "Gerald Fehringer" <[EMAIL PROTECTED]>
> > > > > To: <[EMAIL PROTECTED]>
> > > > > Sent: Monday, September 30, 2002 8:06 AM
> > > > > Subject: [iText-questions] Table as header ?
> > > > >
> > > > >
> > > > > > Hello!
> > > > > >
> > > > > > I have an application which makes use of Tables
> > > > > (com.lowagie.text.Table).
> > > > > > It
> > > > > > get's filled with Chunks, Phrases, Images, .. dynamically. All
> this
> > > > > works
> > > > > > fine.
> > > > > >
> > > > > > Now there is need to add headers/footers to the documents, but
> > > these
> > > > > can
> > > > > be
> > > > > > quite complex. So my idea is to reuse the code already written
> for
> > > > > creating
> > > > > > Tables dynamically and then add such a table as header/footer.
> > > > > >
> > > > > > From what I know I can use PageEvents to add headers/footers to
> the
> > > > > > individual pages, there adding PdfPTables (or text or
templates)
> at
> > > > > > absolute
> > > > > > positions. But the problem I have is that I dont have a
PdfPTable
> > > but
> > > a
> > > > > > Table ..
> > > > > >
> > > > > > Therefore here my question:
> > > > > > Is it possible to somehow take my Table and transform it to a
> > > > > PdfPTable?
> > > > > Or
> > > > > > can I write the Table to a template? Or to an image? Or
anything
> > > else
> > > > > that
> > > > > > allows me to use Table for header/footer?
> > > > > >
> > > > > >
> > > > > > Thanks for all your help,
> > > > > > Gerald.
> > > > > >
> > > > > >
> > > > > >
> > > > > > -------------------------------------------------------
> > > > > > This sf.net email is sponsored by:ThinkGeek
> > > > > > Welcome to geek heaven.
> > > > > > http://thinkgeek.com/sf
> > > > > > _______________________________________________
> > > > > > iText-questions mailing list
> > > > > > [EMAIL PROTECTED]
> > > > > > https://lists.sourceforge.net/lists/listinfo/itext-questions
> > > > >
> > > > >
> > > > >
> > > > > -------------------------------------------------------
> > > > > This sf.net email is sponsored by: DEDICATED SERVERS only $89!
> > > > > Linux or FreeBSD, FREE setup, FAST network. Get your own server
> > > > > today at http://www.ServePath.com/indexfm.htm
> > > > > _______________________________________________
> > > > > iText-questions mailing list
> > > > > [EMAIL PROTECTED]
> > > > > https://lists.sourceforge.net/lists/listinfo/itext-questions <<
> File:
> > > tables.pdf >> << File: com.zip >>
>
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions