iText Pdf Header Removal for particular page

风格不统一 提交于 2019-12-11 08:14:47

问题


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.

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.


回答1:


You can use a 2-pass approach:

  • 1st pass : generate the PDF file without header

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

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;

instead of

int n = reader.getNumberOfPages();


来源:https://stackoverflow.com/questions/10548660/itext-pdf-header-removal-for-particular-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!