Hi, I try to put the footer on each page of pdf which has date string on the
left side and page x of Y on the right side.  However, I got the footer like
the following ==>

05/04/20092                                             Page 1 of 2

Can someone tell me what might cause it? Thanks in advance.

Here is part of my code ==>
(I uploaded the full class and its result here)

    public void onEndPage(PdfWriter writer, Document document) 
        {
                try {
                        PdfContentByte cb = writer.getDirectContent();
                        // compose the footer
                        float textBase = document.bottom() - 20;

                        // show the date footer at the left
                        Date now = new Date();
                        SimpleDateFormat simpleformat = new 
SimpleDateFormat("MM/dd/yyyy");
                        String dateStr = simpleformat.format(now);
                        float dateStrSize = helv.getWidthPoint(dateStr, 12);
                        cb.beginText();
                        cb.setFontAndSize(helv, 12);
                        cb.setTextMatrix(document.left(), textBase);
                        cb.showText(dateStr);
                        cb.endText();
                        cb.addTemplate(tpl, document.left() + dateStrSize, 
textBase);

                        // show the page number footer at the right
                        String text = "Page " + writer.getPageNumber() + " of ";
                        float textSize = helv.getWidthPoint(text, 12);
                        float adjust = helv.getWidthPoint("0", 12);
                        cb.beginText();
                        cb.setFontAndSize(helv, 12);
                        cb.setTextMatrix(document.right() - textSize - adjust, 
textBase);
                        cb.showText(text);
                        cb.endText();
                        cb.addTemplate(tpl, document.right() - adjust, 
textBase);
                }
                catch (Exception ex) {
            throw new ExceptionConverter(ex);
                }
        }

        public void onCloseDocument(PdfWriter writer, Document document) 
        {
        try {
                        tpl.beginText();
                        tpl.setFontAndSize(helv, 12);
                        tpl.setTextMatrix(0, 0);
                        tpl.showText(Integer.toString(writer.getPageNumber() - 
1));
                        tpl.endText();
        }
                catch (Exception ex) {
            throw new ExceptionConverter(ex);
                }
        }



However, I got the footer like the following ==>

05/04/20092                                             Page 2 of 2
http://www.nabble.com/file/p23374583/ClientDetailPDFWorkbook.java
ClientDetailPDFWorkbook.java 
http://www.nabble.com/file/p23374583/cprcPDF.pdf cprcPDF.pdf 
-- 
View this message in context: 
http://www.nabble.com/Footer-problem----date-string-on-the-left-and-page-number-on-the-right-tp23374583p23374583.html
Sent from the iText - General mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations 
Conference from O'Reilly Media. Velocity features a full day of 
expert-led, hands-on workshops and two days of sessions from industry 
leaders in dedicated Performance & Operations tracks. Use code vel09scf 
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to