Hi,

Im using a custom "header" with PdfPageEvent stuff.

Basically, what I'm doing is accepting a fairly complex PdfPTable header,
which has an image and several cells of text.  My code is generalized to
take an "Element" class header, and insert it into the document as a header
using events.

Unfortunately, the way I've done it is to use onStartPage to add the
PdfPTable every time I get an onPageEvent.  This doesnt work so well,
because although it works great for all pages (mostly), it doesnt work great
for the last page.  It always seems to add an additional page somehow, and
Im not sure how to prevent this -- i.e. a blank additional page after
whatever else is there which only contains the header and footer (footer is
like the chapter 1201 page n of m example, header is unique)

Ive tried several work arounds to no avail:
- Using onEndPage (which works for all pages but the first in the case of my
document, but not the first and last -- the last being the big difficulty).
It does
get rid of the extra page, however.
- Inserting a small line of invisible text after the table, so as to avoid
potential weirdness with PdfPTable (no avail)

I cant seem to see how to insert the table like the chapter 1201 example,
which inserts straight text and seems to allocate space for it somehow.  My
insertion method is just Document.add(Element e), but Im beginning to
suspect thats a no-go.  Any other way i could add an element without
overwriting other things space?

Following from there, what I dont understand is why onPageEvent is getting
triggered to make an additional page after the document has ended.  You
mention it is "As a page is being created"...  Heres what I saw in my
logging of pageEvents in a docuemnt that has data from page 2-7 but has
basically a header and empty page for page 8 (no page 9 obviously)
DEBUG (report.HeaderEvent) [] trigger onStartPage for 1
DEBUG (report.HeaderEvent) [] trigger onStartPage for 2
DEBUG (report.HeaderEvent) [] triggering on end page on pagenumber 2
DEBUG (report.HeaderEvent) [] trigger onStartPage for 3
DEBUG (report.HeaderEvent) [] triggering on end page on pagenumber 3
DEBUG (report.HeaderEvent) [] trigger onStartPage for 4
DEBUG (report.HeaderEvent) [] triggering on end page on pagenumber 4
DEBUG (report.HeaderEvent) [] trigger onStartPage for 5
DEBUG (report.HeaderEvent) [] triggering on end page on pagenumber 5
DEBUG (report.HeaderEvent) [] trigger onStartPage for 6
DEBUG (report.HeaderEvent) [] triggering on end page on pagenumber 6
DEBUG (report.HeaderEvent) [] trigger onStartPage for 7
DEBUG (report.HeaderEvent) [] triggering on end page on pagenumber 7
DEBUG (report.HeaderEvent) [] trigger onStartPage for 8
DEBUG (report.HeaderEvent) [] triggering on end page on pagenumber 8
DEBUG (report.HeaderEvent) [] trigger onStartPage for 9
DEBUG (report.HeaderEvent) [] called onCloseDocument

I suspect that my document.add call is triggering another onStartPage event
for the #8, but if that was the case, woudlnt I be getting a double header
at the end or an endless loop (which I'm not).  It doesnt make a lot of
sense for that to be triggered either, since my header isnt pushing text
page page number 7...

Any ideas?  Is this a bug, or am I just doing something really dumb?  Any
help is greatly appreciated!
Tom


_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to