iText 7 - Different footer on last page - Null pointer in PdfDictionary

后端 未结 2 1717
情书的邮戳
情书的邮戳 2021-01-14 11:32

I am trying to implement a footer in iText7, the footer should be different on the last page of the document, I have added an event handler which is called when

2条回答
  •  礼貌的吻别
    2021-01-14 12:09

    I have not used itext before, but the javadoc for onCloseDocument in itext5 says:

    Called when the document is closed. Note that this method is called with the page number equal to the last page plus one.

    could it be that you simply have to change your loop from

    for (int i = 1; i <= document.getPdfDocument().getNumberOfPages(); i++)
    {
    

    to

    for (int i = 1; i < document.getPdfDocument().getNumberOfPages(); i++)
    {
    

    ? (note the i < ... instead of i <= )

提交回复
热议问题