简体   繁体   中英

Have to remove lines in header and footer in pdf using iText java

    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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM