Write a class extending com.lowagie.text.pdf.PdfPageEventHelper.
Pass an instance of this class to the setPageEvent method of PDFWriter.
In the class extending com.lowagie.text.pdf.PdfPageEventHelper
Override onEndPage() , onStartPage(),onOpenDocument(), onCloseDocument() etc.
Within onEndPage() write code similar to below
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
// compose the footer
String text = "Page " + writer.getPageNumber() + " of ";
float textSize = helv.getWidthPoint(text, 12);
float textBase = document.bottom() - 20;
cb.beginText();
cb.setFontAndSize(helv, 12);
float adjust = helv.getWidthPoint("0", 12);
cb.setTextMatrix(document.right() - textSize - adjust, textBase);
cb.showText(text);
cb.endText();
cb.addTemplate(tpl, document.right() - adjust, textBase);
cb.restoreState();
cb.sanityCheck();
---------------------------------------------
Class Variables declared -->
/** A template that will hold the total number of pages. */
public PdfTemplate tpl;
-------------------------------------------
In onOpenDocument()-->
tpl = writer.getDirectContent().createTemplate(100, 100);
tpl.setBoundingBox(new Rectangle(-20, -20, 100, 100));
in onCloseDocument -->
tpl.beginText();
tpl.setFontAndSize(helv, 12);
tpl.setTextMatrix(0, 0);
tpl.showText(Integer.toString(writer.getPageNumber() - 1));
tpl.endText();
tpl.sanityCheck();
Hope this helps...
~Olive
-----Original Message-----
From: Jaya Prabahar [mailto:[email protected]]
Sent: Tuesday, October 26, 2010 3:25 PM
To: [email protected]
Subject: [iText-questions] URGENT - ADDING PAGE NUMBER IN iText 5.0.4
Dear All,
Please help me out fastly. I want to add "page 1 of 3" in
the PDF documents. Please let me know. Also how to add Headers in
version 5.0.4.
Regards,
JP
------------------------------------------------------------------------------
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
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you
------------------------------------------------------------------------------
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