iText Pdf Header删除特定页面 [英] iText Pdf Header Removal for particular page

查看:539
本文介绍了iText Pdf Header删除特定页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iText生成PDF,因为我正在显示页眉和页脚。
现在我想删除特定页面的标题。

I'm generating a PDF with iText, in that I'm displaying a header and footer. Now i want to remove header for a particular page.

例如:如果我生成50页pdf,那么最后50页我不会我想显示标题,
如何实现?

For eg: If I'm generating a 50 pages pdf, for the final 50th I don't want to show header, how could this be achieved?

这是我生成页脚的代码(标题部分已删除)。

Here's my code where I'm generating footer (header part removed).

public class HeaderAndFooter extends PdfPageEventHelper {

public void onEndPage (PdfWriter writer, Document document) {
    Rectangle rect = writer.getBoxSize("art");
    switch(writer.getPageNumber() % 2) {
    case 0:

    case 1:
        ColumnText.showTextAligned(writer.getDirectContent(),
                Element.ALIGN_CENTER, new Phrase(String.format("%d", writer.getPageNumber())),
                300f, 62f, 0);
        break;
    }

}

}

有什么建议吗?在此先感谢。

Any suggestions? Thanks in advance.

推荐答案

您可以使用2遍方式:


  • 第一遍:生成没有标题的PDF文件

  • 1st pass : generate the PDF file without header

第二遍:在标题上标记除了最后一页

2nd pass : stamp the header on all but the last page

看看这个从iText书中获取的例子。你只需要通过N-1首页来调整第二遍:

Have a look at this example taken from the iText book. You'll just have to adapt the second pass by only going through the N-1 first pages:

int n = reader.getNumberOfPages() - 1;

而不是

int n = reader.getNumberOfPages();

这篇关于iText Pdf Header删除特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆