add header to pdf using iText

2019-02-23 23:46发布

问题:

how i can add header to each PDF page using iText 5.0.5.

回答1:

This is covered in chapter 5 of iText In Action, 2nd ed. The code examples are all freely available online. In particular MovieCountries1 and MovieHistory2 both deal with page headers and footers.

It boils down to using a PdfPageEvent implementation (usually derived from PdfPageEventHelper to cut down on boilerplate) to draw into the page's Direct Content during an EndPage (or BeginPage I suppose) event.

You have to know where you want them, and you have to draw using a PdfContentByte instance, so you can't use the high-level Paragraph/Chapter/Chunk/Image/etc classes. You have to draw-this-there, draw-that-here. ColumnText can help a bit... but only for Plain Text. Anything even remotely fancy and you're on your own.



回答2:

See the below link having video to show you.

http://itextpdf.com/book/chapter.php?id=4

For Header-Footer: http://kuujinbo.info/cs/itext.aspx

http://www.codeproject.com/KB/graphics/ITextSharpHelperClass.aspx

Please Vote if this helps to you.



标签: java itext