简体   繁体   English

必须使用iText Java删除pdf中页眉和页脚中的行

[英]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 这是我的标题显示在我的pdf中的输出


HBOM Reports HBOM报告


My footer displayed as like this 我的页脚显示如下


globematics 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. 而且我需要在Center中对齐页眉和页脚文本。

    Just now I started using iText so I don't have any idea in that.Please some help me for this. 刚才我开始使用iText,所以我对此一无所知,请为此提供帮助。 Thanks in advance 提前致谢

You can use setAlignement to center the text, and setBorder to remove the border and add only the one you want. 您可以使用setAlignement将文本居中,使用setBorder删除边框并仅添加所需的边框。

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 正如我在网络上多次看到的那样,不鼓励使用此类,您可以看看页面事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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