tags:

views:

4443

answers:

1

I am creating a header with iText using the HeaderFooter object. The Page Number is always appearing on the second line of the header, even though there is plenty of room on the first line, and I am not explicitly putting a line break there. It seems that this problem only started when upgrading from iText 1.2 to iText 2.1.5, but I didn't notice anything obvious in the iText source code. Has anyone else had this issue, or knows how to solve it?

headString +=  viewReportTitle + "Page: ";
//Setting the second param to true should append a page number at the end of the string
HeaderFooter header = new HeaderFooter(new Paragraph(headString, iTextHeadingFont), true);
header.setAlignment(Element.ALIGN_CENTER);
iTextDoc.setHeader(header);

The output appears like this:

Report Title Page:
1
A: 

For all who are interested, I figured it out. By changing the HeaderFooter parameter to Phrase, from Paragraph, the problem was solved.

Change this line:

HeaderFooter header = new HeaderFooter(new Paragraph(headString, iTextHeadingFont), true);

To this:

HeaderFooter header = new HeaderFooter(new Phrase(headString, iTextHeadingFont), true);

Issue closed!

twpc