Java Mailing List Archive

http://www.junlu.com/

Home » Post all your questions about iText here »

Re: [iText-questions] page number in pdf using iTextSharp

Keith O

2010-09-02

Replies: Find Java Web Hosting

Author LoginPost Reply

Hi,

----------------------------------------
> From: nurettindag@(protected)
> To: nurettindag@(protected)
> Date: Thu, 2 Sep 2010 20:57:20 -0400
> Subject: Re: [iText-questions] page number in pdf using iTextSharp
>
> I just looked at the Java source code and it looks like it is actually a bug
> with Document. Document depends on PdfDocument to set page number in order
> to have the correct value. However, PdfDocument never makes the necessary
> calls to sync the value. That is why it always returns 0. However, as I
> mentioned in the prev e-mail you can use writer as a workaround.

That's incorrect - no a bug, at least not as you described. If you're following the standard method to add the page number by implementing page events, you can try something like this:

public override void OnEndPage(PdfWriter writer, Document document) {
  Rectangle page = document.PageSize;
  ColumnText.ShowTextAligned(
    writer.DirectContent, Element.ALIGN_CENTER,
    new Phrase(string.Format("{0} {1}", HeaderText, document.PageNumber)),
/* x write coordinate => center */
    (page.Left + page.Right) / 2,
/* y write coordinate => top */
    page.Height - document.TopMargin,
    0
  );
}

And you'll see PdfDocument produces the expected results. (where 'HeaderText' above is the header string)
           
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
iText-questions mailing list
iText-questions@(protected)
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
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/
©2008 junlu.com - Jax Systems, LLC, U.S.A.