Detecting first page is pretty straightforward as you mentioned, just
checking pageNumber==1 should be good enough. In order to detect last page
you can make use of the following fact:
onEndPage event is only fired either when iText detects it needs to move to
the next page or when user prompts to move to next page via API. An
exception to this is the last page in which case even though last page is
not full when document is prompted to be closed it will first fire up an
onEndPage event.
Therefore, what I would suggest you do is sometime between after you finish
adding content to pdf and before closing the document make a call to your
custom PdfPageEventHandler to set some sort of flag that coming onEndPage
event is for the last page and go from there on.
Good luck
Nurettin
On Mon, Oct 25, 2010 at 6:31 AM, riffla <[email protected]> wrote:
>
> Hi
>
> Not sure that the subject reflects my question proper, but anyway my
> problem
> is as follows
>
> I need to achieve the following functionality.
> On each page besides the last one I want an attribute (two pairs of label
> and text) to be output in the header of the pages. And besides, on the
> first
> page the layout of these attributes is different from the layout on
> subsequent pages (besides the last page, remember).
>
> And another thing is that I don't know the number of pages ahead, so I need
> to implement this dynamically, probably inside the PdfPageEvent code.
>
> I was thinking of adding the first pair of attributes - not necessary using
> PdfTemplate - in the onEndPage checking for pageNumber == 1 with desired
> layout, and then in the onCloseDocument add the second layout to a
> PdfTemplate.
> But is it possible to add this template only to certain pages, in my case I
> don't want it to be on first or last page? Checking for the first page can
> be handled by adding the template in the overridden onEndPage method but
> how
> do I avoid adding the template to the last page not knowing which page is
> the last one until the document is about to close?
>
> /R
> --
> View this message in context:
> http://itext-general.2136553.n4.nabble.com/Different-PdfTemplates-dynamically-tp3010076p3010076.html
> Sent from the iText - General mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> Nokia and AT&T present the 2010 Calling All Innovators-North America
> contest
> Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in
> marketing
> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
> http://p.sf.net/sfu/nokia-dev2dev
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Many questions posted to this list can (and will) be answered with a
> reference to the iText book: http://www.itextpdf.com/book/
> Please check the keywords list before you ask for examples:
> http://itextpdf.com/themes/keywords.php
>
--
Nurettin DAG
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php