Reputation: 1238
I've used the following code to display header and footer in my pdf using itext.
HeaderFooter header=new HeaderFooter(new Phrase("HBOM Reports"),false);
document.setHeader(header);
HeaderFooter footer=new HeaderFooter(new Phrase("globematics\nSecond line"),false);
document.setFooter(footer);
Here is my header displayed output in my pdf
HBOM Reports
My footer displayed as like this
globematics
second line
Now I don't know why the two lines are printing on my header and footer.
I want to remove the bottom line from my footer and top line from my header. And I need to align both header and footer text in Center.
Just now I started using iText so I don't have any idea in that.Please some help me for this. Thanks in advance
Upvotes: 0
Views: 3944
Reputation: 25613
You can use setAlignement
to center the text, and setBorder
to remove the border and add only the one you want.
HeaderFooter header = new HeaderFooter(new Phrase("HBOM Reports"), false);
header.setAlignment(HeaderFooter.ALIGN_CENTER);
header.setBorder(Rectangle.NO_BORDER);
header.setBorder(Rectangle.BOTTOM);
document.setHeader(header);
HeaderFooter footer = new HeaderFooter(new Phrase("globematics\nSecond line"), false);
footer.setAlignment(HeaderFooter.ALIGN_CENTER);
footer.setBorder(Rectangle.NO_BORDER);
footer.setBorder(Rectangle.TOP);
document.setFooter(footer);
As I have seen multiple times on the web, the use of this class is discouraged, you may take a look at page events
Upvotes: 4