How to add text as a header or footer?

后端 未结 2 1053
故里飘歌
故里飘歌 2020-12-20 02:30

I\'m creating a pdf with iText 5 and want to add a footer. I did everything like the book \"iText in action\" in Chapter 14 says.

There are no errors but the footer

2条回答
  •  鱼传尺愫
    2020-12-20 02:56

    By using showTextAligned method of PdfContentByte We can add footer to our page. Instead of phrase we should pass footer content as string to showTextAligned method as one of the parameter. If you want to format your footer content do before passing it to the method. Below is the sample code.

     PdfContentByte cb = writer.getDirectContent();
     cb.showTextAligned(Element.ALIGN_CENTER, "this is a footer", (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() - 10, 0);
    

提交回复
热议问题